J-Bakuli commented on code in PR #13841:
URL: https://github.com/apache/ignite/pull/13841#discussion_r4679224696
##########
modules/calcite-testing/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -381,6 +387,55 @@ public void testSysSchema() throws Exception {
assertThrows("DROP VIEW IF EXISTS sys.views",
IgniteSQLException.class, msg);
}
+ /**
+ * Tests that a view name with a quote does not run a second statement in
the H2 database,
Review Comment:
Ilja, thank you, I have applied those changes
##########
modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java:
##########
@@ -194,6 +200,206 @@ public void testSchemaEscapeAll() throws Exception {
ignite(0).destroyCache(cfgEsc.getName());
}
+ /**
+ * Tests that a schema name with a quote does not create SCHEMA_INJECTED,
+ * a row is readable through that schema, and destroying the cache drops
the schema.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testSchemaNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String schemaName = "A\";CREATE TABLE PUBLIC.SCHEMA_INJECTED(ID
INT);--";
+
+ String quotedSchema = "\"" + schemaName.replace("\"", "\"\"") + "\"";
+
+ IgniteCache<Integer, Fact> cache =
ignite(0).createCache(cacheConfig("stmtSchema", true, Integer.class, Fact.class)
+ .setSqlSchema("\"" + schemaName + "\""));
+
+ assertH2TableAbsent("SCHEMA_INJECTED");
+
+ cache.put(1, new Fact(1, "v"));
+
+ List<List<?>> rows = cache.query(new SqlFieldsQuery(
+ "select f.name from " + quotedSchema + ".Fact f")).getAll();
+
+ assertEquals(1, rows.size());
+ assertEquals("v", rows.get(0).get(0));
+
+ ignite(0).destroyCache(cache.getName());
+
+ assertH2TableAbsent("SCHEMA_INJECTED");
+
+ assertFalse("Schema is not dropped in H2", h2SchemaExists(schemaName));
+ }
+
+ /**
+ * Tests that a table name with a quote does not create TABLE_INJECTED,
+ * a row is readable through that table, and destroying the cache drops
the table.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testTableNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String tblName = "A\";CREATE TABLE PUBLIC.TABLE_INJECTED(ID INT);--";
+
+ String quotedTbl = "\"" + tblName.replace("\"", "\"\"") + "\"";
+
+ QueryEntity entity = new QueryEntity()
+ .setTableName(tblName)
+ .setKeyType(Integer.class.getName())
+ .setValueFieldName("name")
+ .setValueType(String.class.getName())
+ .addQueryField("name", String.class.getName(), null);
+
+ IgniteCache<Integer, String> cache = ignite(0).createCache(new
CacheConfiguration<Integer, String>("stmtTable")
+ .setQueryEntities(Collections.singletonList(entity)));
+
+ assertH2TableAbsent("TABLE_INJECTED");
+
+ cache.put(1, "v");
+
+ List<List<?>> rows = cache.query(new SqlFieldsQuery(
+ "select name from " + quotedTbl)).getAll();
+
+ assertEquals(1, rows.size());
+ assertEquals("v", rows.get(0).get(0));
+
+ ignite(0).destroyCache(cache.getName());
+
+ assertH2TableAbsent("TABLE_INJECTED");
+
+ assertFalse("Table is not dropped in H2", h2TableExists(tblName));
+ }
+
+ /**
+ * Tests that creating a cache with this column name does not create
COLUMN_INJECTED,
+ * the index on that column is created, and a row is readable through that
column.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testColumnNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String colName = "C\" VARCHAR);CREATE TABLE PUBLIC.COLUMN_INJECTED(ID
INT);--";
+
+ String quotedCol = "\"" + colName.replace("\"", "\"\"") + "\"";
+
+ QueryEntity entity = new QueryEntity(Integer.class.getName(),
Fact.class.getName())
+ .setTableName("FACT")
+ .addQueryField("id", Integer.class.getName(), null)
+ .addQueryField("name", String.class.getName(), colName)
+ .setIndexes(Collections.singletonList(new
QueryIndex("name").setName("NAME_IDX")));
+
+ IgniteCache<Integer, Fact> cache = ignite(0).createCache(new
CacheConfiguration<Integer, Fact>("colCache")
+ .setSqlSchema("COL_SCHEMA")
+ .setQueryEntities(Collections.singletonList(entity)));
+
+ assertH2TableAbsent("COLUMN_INJECTED");
+
+ assertTrue("Index is not created in H2", h2IndexExists("COL_SCHEMA",
"NAME_IDX"));
+
+ cache.put(1, new Fact(1, "v"));
+
+ List<List<?>> rows = cache.query(new SqlFieldsQuery(
+ "select " + quotedCol + " from COL_SCHEMA.FACT where " + quotedCol
+ " = ?").setArgs("v")).getAll();
+
+ assertEquals(1, rows.size());
+ assertEquals("v", rows.get(0).get(0));
+ }
+
+ /**
+ * Tests that creating and dropping an index with this name does not
create INDEX_INJECTED,
+ * and the index is created and dropped in H2.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testIndexNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String idxName = "I\";CREATE TABLE PUBLIC.INDEX_INJECTED(ID INT);--";
+
+ String quotedIdx = "\"" + idxName.replace("\"", "\"\"") + "\"";
+
+ QueryEntity entity = new QueryEntity(Integer.class.getName(),
Fact.class.getName())
+ .setTableName("FACT")
+ .addQueryField("id", Integer.class.getName(), null)
+ .addQueryField("name", String.class.getName(), null)
+ .setIndexes(Collections.singletonList(new
QueryIndex("name").setName(idxName)));
+
+ IgniteCache<Integer, Fact> cache = ignite(0).createCache(new
CacheConfiguration<Integer, Fact>("idxCache")
+ .setSqlSchema("IDX_SCHEMA")
+ .setQueryEntities(Collections.singletonList(entity)));
+
+ assertH2TableAbsent("INDEX_INJECTED");
+
+ assertTrue("Index is not created in H2", h2IndexExists("IDX_SCHEMA",
idxName));
+
+ cache.query(new SqlFieldsQuery("DROP INDEX IDX_SCHEMA." +
quotedIdx)).getAll();
+
+ assertH2TableAbsent("INDEX_INJECTED");
+
+ assertFalse("Index is not dropped in H2", h2IndexExists("IDX_SCHEMA",
idxName));
+ }
+
+ /**
+ * @param tblName Table name.
+ */
+ private void assertH2TableAbsent(String tblName) throws Exception {
+ assertFalse("Unexpected H2 table: " + tblName, h2TableExists(tblName));
+ }
+
+ /**
+ * @param schemaName Schema name.
+ * @return {@code True} if H2 has the schema.
+ */
+ private boolean h2SchemaExists(String schemaName) throws Exception {
+ return h2RowExists(
+ "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE
SCHEMA_NAME = ?",
+ schemaName);
+ }
+
+ /**
+ * @param tblName Table name.
+ * @return {@code True} if H2 has the table.
+ */
+ private boolean h2TableExists(String tblName) throws Exception {
+ return h2RowExists(
+ "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME
= ?",
+ tblName);
+ }
+
+ /**
+ * @param schemaName Schema name.
Review Comment:
Ilja, thank you, I have applied those changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]