You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/08/03 23:19:09 UTC

[GitHub] [phoenix] swaroopak commented on a change in pull request #848: Phoenix-5947 Add tests and extensions to Schema Extraction Tool utility

swaroopak commented on a change in pull request #848:
URL: https://github.com/apache/phoenix/pull/848#discussion_r464711039



##########
File path: phoenix-tools/src/it/java/org/apache/phoenix/schema/SchemaExtractionToolIT.java
##########
@@ -58,156 +130,251 @@ public void testCreateTableStatement_tenant() throws Exception {
         String viewName = generateUniqueName();
         String schemaName = generateUniqueName();
         String tenantId = "abc";
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
-        String properties = "TTL=2592000,IMMUTABLE_ROWS=true,DISABLE_WAL=true";
-        SchemaExtractionTool set;
+        String createTableStmt = "CREATE TABLE "+pTableFullName + "(k BIGINT NOT NULL PRIMARY KEY, "
+                + "v1 VARCHAR, v2 VARCHAR)";
         String viewFullName = SchemaUtil.getQualifiedTableName(schemaName, viewName);
-        String createView = "CREATE VIEW "+viewFullName + "(id1 BIGINT, id2 BIGINT NOT NULL, "
+        String createViewStmt = "CREATE VIEW "+viewFullName + "(id1 BIGINT, id2 BIGINT NOT NULL, "
                 + "id3 VARCHAR NOT NULL CONSTRAINT PKVIEW PRIMARY KEY (id2, id3 DESC)) "
                 + "AS SELECT * FROM "+pTableFullName;
 
-        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-
-            conn.createStatement().execute("CREATE TABLE "+pTableFullName + "(k BIGINT NOT NULL PRIMARY KEY, "
-                    + "v1 VARCHAR, v2 VARCHAR)"
-                    + properties);
-            set = new SchemaExtractionTool();
-            set.setConf(conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration());
-            conn.commit();
-        }
-        try (Connection conn = getTenantConnection(getUrl(), tenantId)) {
-            conn.createStatement().execute(createView);
-            conn.commit();
-        }
-        String [] args = {"-tb", viewName, "-s", schemaName, "-t", tenantId};
-        set.run(args);
-        Assert.assertEquals(createView.toUpperCase(), set.getOutput().toUpperCase());
+        List<String> queries1 = new ArrayList<String>(){};
+        queries1.add(createTableStmt);
+        runSchemaExtractionTool(schemaName, tableName, null, queries1);
+        List<String> queries2 = new ArrayList<String>();
+        queries2.add(createViewStmt);
+        String result2 = runSchemaExtractionTool(schemaName, viewName, tenantId, queries2);
+        Assert.assertEquals(createViewStmt.toUpperCase(), result2.toUpperCase());
     }
 
-    private Connection getTenantConnection(String url, String tenantId) throws SQLException {
-        Properties props = new Properties();
-        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
-        return DriverManager.getConnection(url, props);
+    @Test
+    public void testSaltedTableStatement() throws Exception {
+        String tableName = generateUniqueName();
+        String schemaName = generateUniqueName();
+        String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
+        String query = "create table " + pTableFullName +
+                "(a_integer integer not null CONSTRAINT pk PRIMARY KEY (a_integer)) SALT_BUCKETS=16";
+        List<String> queries = new ArrayList<String>(){};
+        queries.add(query);
+        String result = runSchemaExtractionTool(schemaName, tableName, null, queries);
+        Assert.assertTrue(getProperties(result).contains("SALT_BUCKETS=16"));
     }
 
     @Test
-    public void testCreateIndexStatement() throws Exception {
+    public void testCreateTableWithPKConstraint() throws Exception {
         String tableName = generateUniqueName();
         String schemaName = generateUniqueName();
-        String indexName = generateUniqueName();
-        String indexName1 = generateUniqueName();
-        String indexName2 = generateUniqueName();
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String properties = "TTL=2592000,IMMUTABLE_ROWS=true,DISABLE_WAL=true";
-
-        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
-
-            String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
-            conn.createStatement().execute("CREATE TABLE "+pTableFullName + "(k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"
-                    + properties);
-
-            String createIndexStatement = "CREATE INDEX "+indexName + " ON "+pTableFullName+"(v1 DESC) INCLUDE (v2)";
-
-            String createIndexStatement1 = "CREATE INDEX "+indexName1 + " ON "+pTableFullName+"(v2 DESC) INCLUDE (v1)";
-
-            String createIndexStatement2 = "CREATE INDEX "+indexName2 + " ON "+pTableFullName+"(k)";
-
-            conn.createStatement().execute(createIndexStatement);
-            conn.createStatement().execute(createIndexStatement1);
-            conn.createStatement().execute(createIndexStatement2);
-            conn.commit();
-            SchemaExtractionTool set = new SchemaExtractionTool();
-            set.setConf(conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration());
-
-            String [] args = {"-tb", indexName, "-s", schemaName};
-            set.run(args);
-            Assert.assertEquals(createIndexStatement.toUpperCase(), set.getOutput().toUpperCase());
-
-            String [] args1 = {"-tb", indexName1, "-s", schemaName};
-            set.run(args1);
-            Assert.assertEquals(createIndexStatement1.toUpperCase(), set.getOutput().toUpperCase());
-
-            String [] args2 = {"-tb", indexName2, "-s", schemaName};
-            set.run(args2);
-            Assert.assertEquals(createIndexStatement2.toUpperCase(), set.getOutput().toUpperCase());
-        }
+        String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
+        String query = "create table " + pTableFullName +
+                "(a_char CHAR(15) NOT NULL, " +
+                "b_char CHAR(15) NOT NULL, " +
+                "c_bigint BIGINT NOT NULL CONSTRAINT PK PRIMARY KEY (a_char, b_char, c_bigint)) IMMUTABLE_ROWS=TRUE";
+        List<String> queries = new ArrayList<String>(){};
+        queries.add(query);
+        String result = runSchemaExtractionTool(schemaName, tableName, null, queries);
+        Assert.assertEquals(query.toUpperCase(), result.toUpperCase());
     }
 
     @Test
-    public void testCreateViewStatement() throws Exception {
+    public void testCreateTableWithArrayColumn() throws Exception {
         String tableName = generateUniqueName();
         String schemaName = generateUniqueName();
-        String viewName = generateUniqueName();
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        String properties = "TTL=2592000,IMMUTABLE_ROWS=true,DISABLE_WAL=true";
+        String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
+        String query = "create table " + pTableFullName +
+                "(a_char CHAR(15) NOT NULL, " +
+                "b_char CHAR(10) NOT NULL, " +
+                "c_var_array VARCHAR ARRAY, " +
+                "d_char_array CHAR(15) ARRAY[3] CONSTRAINT PK PRIMARY KEY (a_char, b_char)) " +
+                "TTL=2592000, IMMUTABLE_STORAGE_SCHEME=ONE_CELL_PER_COLUMN, REPLICATION_SCOPE=1";
+        List<String> queries = new ArrayList<String>(){};
+        queries.add(query);
+        String result = runSchemaExtractionTool(schemaName, tableName, null, queries);
+        Assert.assertEquals(query.toUpperCase(), result.toUpperCase());
+    }
 
-        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+    @Test
+    public void testCreateTableWithNonDefaultColumnFamily() throws Exception {
+        String tableName = generateUniqueName();
+        String schemaName = generateUniqueName();
+        String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
+        String query = "create table " + pTableFullName +
+                "(a_char CHAR(15) NOT NULL, " +
+                "b_char CHAR(10) NOT NULL, " +
+                "\"av\".\"_\" CHAR(1), " +
+                "\"bv\".\"_\" CHAR(1), " +
+                "\"cv\".\"_\" CHAR(1), " +
+                "\"dv\".\"_\" CHAR(1) CONSTRAINT PK PRIMARY KEY (a_char, b_char)) " +
+                "TTL=1209600, IMMUTABLE_ROWS=true, IMMUTABLE_STORAGE_SCHEME=ONE_CELL_PER_COLUMN, SALT_BUCKETS=16, MULTI_TENANT=true";
+        List<String> queries = new ArrayList<String>(){};
+        queries.add(query);
+        String result = runSchemaExtractionTool(schemaName, tableName, null, queries);
+        Assert.assertEquals(query.toUpperCase(), result.toUpperCase());
+    }
 
-            String pTableFullName = SchemaUtil.getQualifiedTableName(schemaName, tableName);
-            conn.createStatement().execute("CREATE TABLE "+pTableFullName + "(k BIGINT NOT NULL PRIMARY KEY, "
-                    + "v1 VARCHAR, v2 VARCHAR)"
-                    + properties);
-            String viewFullName = SchemaUtil.getQualifiedTableName(schemaName, viewName);
-            String viewFullName1 = SchemaUtil.getQualifiedTableName(schemaName, viewName+"1");
+    @Test
+    public void testCreateTableWithUniversalCFProperties() throws Exception {

Review comment:
       I feel this and testCreateTableWithNonDefaultColumnFamily can be clubbed into one test?




----------------------------------------------------------------
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:
users@infra.apache.org