haridsv commented on code in PR #1866:
URL: https://github.com/apache/phoenix/pull/1866#discussion_r1562010913


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/CDCDefinitionIT.java:
##########
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.util.CDCUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+import static 
org.apache.phoenix.schema.PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@RunWith(Parameterized.class)
+@Category(ParallelStatsDisabledTest.class)
+public class CDCDefinitionIT extends CDCBaseIT {
+    private final boolean forView;
+
+    public CDCDefinitionIT(boolean forView) {
+        this.forView = forView;
+    }
+
+    @Parameterized.Parameters(name = "forView={0}")
+    public static synchronized Collection<Boolean[]> data() {
+        return Arrays.asList(new Boolean[][] {
+                { false}, { true }
+        });
+    }
+
+    @Test
+    public void testCreate() throws Exception {
+        Connection conn = newConnection();
+        String tableName = generateUniqueName();
+        String datatableName = tableName;
+        conn.createStatement().execute(
+                "CREATE TABLE  " + tableName + " ( k INTEGER PRIMARY KEY," + " 
v1 INTEGER,"
+                        + " v2 DATE)");
+        if (forView) {
+            String viewName = generateUniqueName();
+            conn.createStatement().execute(
+                    "CREATE VIEW " + viewName + " AS SELECT * FROM " + 
tableName);
+            tableName = viewName;
+        }
+        String cdcName = generateUniqueName();
+        String cdc_sql;
+
+        try {
+            conn.createStatement().execute("CREATE CDC " + cdcName
+                    + " ON NON_EXISTENT_TABLE");
+            fail("Expected to fail due to non-existent table");
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.TABLE_UNDEFINED.getErrorCode(), 
e.getErrorCode());
+        }
+
+        cdc_sql = "CREATE CDC " + cdcName + " ON " + tableName;
+        createCDCAndWait(conn, tableName, cdcName, cdc_sql, null, null, null);
+        assertCDCState(conn, cdcName, null, 3);
+        assertNoResults(conn, cdcName);
+
+        try {
+            conn.createStatement().execute(cdc_sql);
+            fail("Expected to fail due to duplicate index");
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.TABLE_ALREADY_EXIST.getErrorCode(), 
e.getErrorCode());
+            assertTrue(e.getMessage().endsWith(cdcName));
+        }
+
+        conn.createStatement().execute("CREATE CDC IF NOT EXISTS " + cdcName + 
" ON " + tableName +
+                " INCLUDE (pre, post) INDEX_TYPE=g");
+
+        cdcName = generateUniqueName();
+        cdc_sql = "CREATE CDC " + cdcName + " ON " + tableName + " INCLUDE 
(pre, post)";
+        createCDCAndWait(conn, tableName, cdcName, cdc_sql, 
PTable.IndexType.UNCOVERED_GLOBAL);
+        assertCDCState(conn, cdcName, "PRE,POST", 3);
+        assertPTable(cdcName, new HashSet<>(
+                Arrays.asList(PTable.CDCChangeScope.PRE, 
PTable.CDCChangeScope.POST)), tableName,
+                datatableName);
+        assertNoResults(conn, cdcName);
+
+        cdcName = generateUniqueName();
+        cdc_sql = "CREATE CDC " + cdcName + " ON " + tableName + " 
INDEX_TYPE=l";
+        createCDCAndWait(conn, tableName, cdcName, cdc_sql, 
PTable.IndexType.LOCAL);
+        assertCDCState(conn, cdcName, null, 2);
+        assertPTable(cdcName, null, tableName, datatableName);
+        assertNoResults(conn, cdcName);
+
+        conn.close();
+    }
+
+    @Test
+    public void testCreateWithSalt() throws Exception {
+        // Indexes on views don't support salt buckets and is currently 
silently ignored.
+        if (forView) {
+            return;
+        }
+
+        // {data table bucket count, CDC bucket count}
+        Integer[][] saltingConfigs = new Integer[][] {
+                new Integer[]{null, 2},
+                new Integer[]{0, 2},
+                new Integer[]{4, null},
+                new Integer[]{4, 1},
+                new Integer[]{4, 0},
+                new Integer[]{4, 2}
+        };
+
+        for (Integer[] saltingConfig: saltingConfigs) {
+            try (Connection conn = newConnection()) {
+                String tableName = generateUniqueName();
+                createTable(conn, "CREATE TABLE  " + tableName +
+                                " ( k INTEGER PRIMARY KEY, v1 INTEGER, v2 
DATE)",
+                                null, false, saltingConfig[0], false, null);
+                assertSaltBuckets(conn, tableName, saltingConfig[0]);
+
+                String cdcName = generateUniqueName();
+                String cdc_sql = "CREATE CDC " + cdcName + " ON " + tableName;
+                createCDCAndWait(conn, tableName, cdcName, cdc_sql, null,
+                        saltingConfig[1], null);
+                try {
+                    assertCDCState(conn, cdcName, null, 3);
+                    // Index inherits table salt buckets.

Review Comment:
   It is meant for the next line, will move it.



-- 
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]

Reply via email to