phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vincentp...@apache.org
Subject phoenix git commit: PHOENIX-4957 Add NO_INDEX hint so IndexTool uses the data table instead of index table
Date Mon, 08 Oct 2018 23:38:34 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master ad29c1cea -> f7b053ac4


PHOENIX-4957 Add NO_INDEX hint so IndexTool uses the data table instead of index table


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f7b053ac
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f7b053ac
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f7b053ac

Branch: refs/heads/master
Commit: f7b053ac4b636c9b41d5d025d0db1a8b9d3de06d
Parents: ad29c1c
Author: Vincent Poon <vincentpoon@apache.org>
Authored: Mon Oct 8 16:38:09 2018 -0700
Committer: Vincent Poon <vincentpoon@apache.org>
Committed: Mon Oct 8 16:38:30 2018 -0700

----------------------------------------------------------------------
 .../phoenix/compile/PostIndexDDLCompiler.java   |  2 +-
 .../compile/PostIndexDDLCompilerTest.java       | 68 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f7b053ac/phoenix-core/src/main/java/org/apache/phoenix/compile/PostIndexDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostIndexDDLCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostIndexDDLCompiler.java
index b3cedf6..1bd3aed 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostIndexDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostIndexDDLCompiler.java
@@ -104,7 +104,7 @@ public class PostIndexDDLCompiler {
         updateStmtStr.append("UPSERT /*+ NO_INDEX */ INTO ").append(schemaName.length() ==
0 ? "" : '"' + schemaName + "\".").append('"').append(tableName).append("\"(")
            .append(indexColumns).append(") ");
         final StringBuilder selectQueryBuilder = new StringBuilder();
-        selectQueryBuilder.append(" SELECT ").append(dataColumns).append(" FROM ")
+        selectQueryBuilder.append(" SELECT /*+ NO_INDEX */ ").append(dataColumns).append("
FROM ")
         .append(schemaName.length() == 0 ? "" : '"' + schemaName + "\".").append('"').append(dataTable.getTableName().getString()).append('"');
         this.selectQuery = selectQueryBuilder.toString();
         updateStmtStr.append(this.selectQuery);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f7b053ac/phoenix-core/src/test/java/org/apache/phoenix/compile/PostIndexDDLCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/PostIndexDDLCompilerTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/compile/PostIndexDDLCompilerTest.java
new file mode 100644
index 0000000..9df2fec
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/PostIndexDDLCompilerTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTableKey;
+import org.apache.phoenix.schema.TableRef;
+import org.junit.Test;
+
+public class PostIndexDDLCompilerTest extends BaseConnectionlessQueryTest {
+
+    @Test
+    public void testHintInSubquery() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            setupTables(conn);
+            PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
+            String query = "UPSERT /*+ NO_INDEX */ INTO T(k, v1) SELECT /*+ NO_INDEX */ 
k,v1 FROM T WHERE v1 = '4'";
+            MutationPlan plan = stmt.compileMutation(query);
+            assertEquals("T", plan.getQueryPlan().getTableRef().getTable().getTableName().getString());
+            query = "UPSERT INTO T(k, v1) SELECT /*+ NO_INDEX */  k,v1 FROM T WHERE v1 =
'4'";
+            plan = stmt.compileMutation(query);
+            // TODO the following should actually use data table T if we supported hints
in subqueries
+            assertEquals("IDX", plan.getQueryPlan().getTableRef().getTable().getTableName().getString());
+        }
+    }
+
+    @Test
+    public void testCompile() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            setupTables(conn);
+            PhoenixConnection pConn = conn.unwrap(PhoenixConnection.class);
+            PTable pDataTable = pConn.getTable(new PTableKey(null, "T"));
+            PostIndexDDLCompiler compiler = new PostIndexDDLCompiler(pConn, new TableRef(pDataTable));
+            MutationPlan plan = compiler.compile(pConn.getTable(new PTableKey(null, "IDX")));
+            assertEquals("T", plan.getQueryPlan().getTableRef().getTable().getTableName().getString());
+        }
+    }
+
+    private void setupTables(Connection conn) throws SQLException {
+        conn.createStatement().execute("CREATE TABLE T (k VARCHAR NOT NULL PRIMARY KEY, v1
CHAR(15), v2 VARCHAR)");
+        conn.createStatement().execute("CREATE INDEX IDX ON T(v1, v2)");
+    }
+
+}


Mime
View raw message