stoty commented on code in PR #1850:
URL: https://github.com/apache/phoenix/pull/1850#discussion_r1517205871


##########
phoenix-core-client/src/main/java/org/apache/phoenix/compile/SplitKeyUtil.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.compile;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.BindParseNode;
+import org.apache.phoenix.parse.ParseNode;
+import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.sql.SQLException;
+import java.util.List;
+
+public class SplitKeyUtil {

Review Comment:
   Do we need a new Util class ?
   Do we have an existing Util class that would make sense for this ?



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java:
##########
@@ -134,6 +134,51 @@ protected BaseIndexIT(boolean localIndex, boolean 
uncovered, boolean mutable, St
         this.tableDDLOptions = optionBuilder.toString();
     }
 
+    @Test
+    public void testCreateIndexWithRowValueConstructorSplitKeys() throws 
Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String tableName = "TBL_" + generateUniqueName();
+        String indexName = "IND_" + generateUniqueName();
+        String fullTableName = 
SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
+        String fullIndexName = 
SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
+
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(false);
+            String splitKeys = "('foo', 'a', 1, 100, 1.0, 
TO_DATE('2024-01-01')), " +
+                    "('john', 'b', 2, 101, 2.0, TO_DATE('2024-01-01')), " +
+                    "('tom', 'c', 3, 102, 3.0, TO_DATE('2024-01-01'))";
+            String ddl ="CREATE TABLE " + fullTableName + 
TestUtil.TEST_TABLE_SCHEMA + tableDDLOptions + " SPLIT ON (" +
+                    splitKeys + ")";
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            String indexSplitKeys = "('a',111, 'foo', 'a', 1, 100, 1.0, 
TO_DATE('2024-01-01')), " +
+                    "('e','222','john', 'b', 2, 101, 2.0, 
TO_DATE('2024-01-01')), " +
+                    "('i', '333', 'tom', 'c', 3, 102, 3.0, 
TO_DATE('2024-01-01'))";
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + (uncovered ? 
"UNCOVERED" : "")
+                    + " INDEX " + indexName + " ON " + fullTableName
+                    + " (char_col1 ASC, int_col1 ASC)"
+                    + (uncovered ? "" : " INCLUDE (long_col1, long_col2)") + 
(localIndex ? "" :
+                    " SPLIT ON (" + indexSplitKeys + ")");
+            stmt.execute(ddl);
+
+            String query = "SELECT d.char_col1, int_col1 from " + 
fullTableName + " as d";
+            ResultSet rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("chara", rs.getString(1));
+            assertEquals("chara", rs.getString("char_col1"));
+            assertEquals(2, rs.getInt(2));
+            assertTrue(rs.next());
+            assertEquals("chara", rs.getString(1));
+            assertEquals(3, rs.getInt(2));
+            assertTrue(rs.next());
+            assertEquals("chara", rs.getString(1));
+            assertEquals(4, rs.getInt(2));
+            assertFalse(rs.next());
+            conn.createStatement().execute("DROP INDEX " + indexName + " ON " 
+ fullTableName);

Review Comment:
   Nit: We already have a stmt object. We could also create the stmt in the 
try-with-reources block.



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java:
##########
@@ -134,6 +134,51 @@ protected BaseIndexIT(boolean localIndex, boolean 
uncovered, boolean mutable, St
         this.tableDDLOptions = optionBuilder.toString();
     }
 
+    @Test
+    public void testCreateIndexWithRowValueConstructorSplitKeys() throws 
Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String tableName = "TBL_" + generateUniqueName();
+        String indexName = "IND_" + generateUniqueName();
+        String fullTableName = 
SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
+        String fullIndexName = 
SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
+
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(false);
+            String splitKeys = "('foo', 'a', 1, 100, 1.0, 
TO_DATE('2024-01-01')), " +
+                    "('john', 'b', 2, 101, 2.0, TO_DATE('2024-01-01')), " +
+                    "('tom', 'c', 3, 102, 3.0, TO_DATE('2024-01-01'))";
+            String ddl ="CREATE TABLE " + fullTableName + 
TestUtil.TEST_TABLE_SCHEMA + tableDDLOptions + " SPLIT ON (" +
+                    splitKeys + ")";
+            Statement stmt = conn.createStatement();
+            stmt.execute(ddl);
+            BaseTest.populateTestTable(fullTableName);
+            String indexSplitKeys = "('a',111, 'foo', 'a', 1, 100, 1.0, 
TO_DATE('2024-01-01')), " +
+                    "('e','222','john', 'b', 2, 101, 2.0, 
TO_DATE('2024-01-01')), " +
+                    "('i', '333', 'tom', 'c', 3, 102, 3.0, 
TO_DATE('2024-01-01'))";
+            ddl = "CREATE " + (localIndex ? "LOCAL" : "") + (uncovered ? 
"UNCOVERED" : "")
+                    + " INDEX " + indexName + " ON " + fullTableName
+                    + " (char_col1 ASC, int_col1 ASC)"
+                    + (uncovered ? "" : " INCLUDE (long_col1, long_col2)") + 
(localIndex ? "" :
+                    " SPLIT ON (" + indexSplitKeys + ")");
+            stmt.execute(ddl);
+

Review Comment:
   We could check the regions and start keys explicitly.
   I think that there is already test code for that and we'd just need to use / 
copy that.



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