alex-plekhanov commented on a change in pull request #6916: IGNITE-12213: Sql objects system views. URL: https://github.com/apache/ignite/pull/6916#discussion_r331010446
########## File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/metric/SqlViewExporterSpiTest.java ########## @@ -332,6 +339,162 @@ public void testTransactions() throws Exception { assertTrue(res); } + /** */ + @Test + public void testSchemas() throws Exception { + try (IgniteEx g = startGrid(new IgniteConfiguration().setSqlSchemas("MY_SCHEMA", "ANOTHER_SCHEMA"))) { + SystemView<SqlSchemaView> schemasSysView = g.context().systemView().view(SQL_SCHEMA_VIEW); + + Set<String> schemaFromSysView = new HashSet<>(); + + schemasSysView.forEach(v -> schemaFromSysView.add(v.name())); + + HashSet<String> expSchemas = new HashSet<>(asList("MY_SCHEMA", "ANOTHER_SCHEMA", "SYS", "PUBLIC")); + + assertEquals(schemaFromSysView, expSchemas); + + List<List<?>> schemas = execute(g, "SELECT * FROM SYS.SCHEMAS"); + + schemaFromSysView.clear(); + schemas.forEach(s -> schemaFromSysView.add(s.get(0).toString())); + + assertEquals(schemaFromSysView, expSchemas); + } + } + + /** */ + @Test + public void testViews() throws Exception { + Set<String> expViews = new HashSet<>(asList( + "METRICS", + "SERVICES", + "CACHE_GROUPS", + "CACHES", + "TASKS", + "LOCAL_SQL_QUERY_HISTORY", + "NODES", + "SCHEMAS", + "NODE_METRICS", + "BASELINE_NODES", + "INDEXES", + "LOCAL_CACHE_GROUPS_IO", + "LOCAL_SQL_RUNNING_QUERIES", + "NODE_ATTRIBUTES", + "TABLES", + "CLIENT_CONNECTIONS", + "VIEWS", + "TABLE_COLUMNS", + "VIEW_COLUMNS", + "TRANSACTIONS" + )); + + Set<String> actViews = new HashSet<>(); + + List<List<?>> res = execute(ignite, "SELECT * FROM SYS.VIEWS"); + + for (List<?> row : res) + actViews.add(row.get(0).toString()); + + assertEquals(expViews, actViews); + } + + /** */ + @Test + public void testTable() throws Exception { + assertTrue(execute(ignite, "SELECT * FROM SYS.TABLES").isEmpty()); + + execute(ignite, "CREATE TABLE T1(ID LONG PRIMARY KEY, NAME VARCHAR)"); + + List<List<?>> res = execute(ignite, "SELECT * FROM SYS.TABLES"); + + assertEquals(1, res.size()); + + List tbl = res.get(0); + + int cacheId = cacheId("SQL_PUBLIC_T1"); + String cacheName = "SQL_PUBLIC_T1"; + + assertEquals("T1", tbl.get(0)); //TABLE_NAME + assertEquals(DFLT_SCHEMA, tbl.get(1)); //SCHEMA_NAME + assertEquals(cacheName, tbl.get(2)); //CACHE_NAME + assertEquals(cacheId, tbl.get(3)); //CACHE_ID + assertNull(tbl.get(4)); //AFFINITY_KEY_COLUMN + assertEquals("ID", tbl.get(5)); //KEY_ALIAS + assertNull(tbl.get(6)); //VALUE_ALIAS + assertEquals("java.lang.Long", tbl.get(7)); //KEY_TYPE_NAME + assertNotNull(tbl.get(8)); //VALUE_TYPE_NAME + + execute(ignite, "CREATE TABLE T2(ID LONG PRIMARY KEY, NAME VARCHAR)"); + + assertEquals(2, execute(ignite, "SELECT * FROM SYS.TABLES").size()); + + execute(ignite, "DROP TABLE T1"); + execute(ignite, "DROP TABLE T2"); + + assertTrue(execute(ignite, "SELECT * FROM SYS.TABLES").isEmpty()); + } + + /** */ + @Test + public void testTableColumns() throws Exception { + assertTrue(execute(ignite, "SELECT * FROM SYS.TABLE_COLUMNS").isEmpty()); + + execute(ignite, "CREATE TABLE T1(ID LONG PRIMARY KEY, NAME VARCHAR(40))"); + + Set<?> actCols = execute(ignite, "SELECT * FROM SYS.TABLE_COLUMNS") + .stream() + .map(l -> l.get(0)) + .collect(Collectors.toSet()); + + assertEquals(new HashSet<>(asList("ID", "NAME", "_KEY", "_VAL")), actCols); + + execute(ignite, "CREATE TABLE T2(ID LONG PRIMARY KEY, NAME VARCHAR(50))"); + + List<List<?>> expRes = asList( + asList("ID", "T1", "PUBLIC", false, false, "null", true, true, -1, -1, Long.class.getName()), + asList("NAME", "T1", "PUBLIC", false, false, "null", true, false, 40, -1, String.class.getName()), + asList("_KEY", "T1", "PUBLIC", true, false, null, false, true, -1, -1, null), + asList("_VAL", "T1", "PUBLIC", false, false, null, true, false, -1, -1, null), + asList("ID", "T2", "PUBLIC", false, false, "null", true, true, -1, -1, Long.class.getName()), + asList("NAME", "T2", "PUBLIC", false, false, "null", true, false, 50, -1, String.class.getName()), + asList("_KEY", "T2", "PUBLIC", true, false, null, false, true, -1, -1, null), + asList("_VAL", "T2", "PUBLIC", false, false, null, true, false, -1, -1, null) + ); + + List<List<?>> res = execute(ignite, "SELECT * FROM SYS.TABLE_COLUMNS ORDER BY TABLE_NAME, COLUMN_NAME"); + + assertEquals(expRes, res); + + execute(ignite, "DROP TABLE T1"); + execute(ignite, "DROP TABLE T2"); + + assertTrue(execute(ignite, "SELECT * FROM SYS.TABLE_COLUMNS").isEmpty()); + } + + /** */ + @Test + public void testViewColumns() throws Exception { + execute(ignite, "SELECT * FROM SYS.VIEW_COLUMNS"); Review comment: What are we testing here? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services