phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: PHOENIX-2819 Remove problematic method ValueSchemaBuilder.addField(Field)
Date Tue, 05 Apr 2016 17:26:08 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 8916eb791 -> 3420a973c


PHOENIX-2819 Remove problematic method ValueSchemaBuilder.addField(Field)


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

Branch: refs/heads/master
Commit: 3420a973c3fbe5ee4483216e54596869665c7cc9
Parents: 8916eb7
Author: maryannxue <maryann.xue@gmail.com>
Authored: Tue Apr 5 13:25:55 2016 -0400
Committer: maryannxue <maryann.xue@gmail.com>
Committed: Tue Apr 5 13:25:55 2016 -0400

----------------------------------------------------------------------
 .../phoenix/end2end/index/ViewIndexIT.java      | 72 ++++++++++++++++++--
 .../apache/phoenix/index/IndexMaintainer.java   |  3 +-
 .../org/apache/phoenix/schema/ValueSchema.java  |  5 --
 3 files changed, 67 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3420a973/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 79b776c..34094d5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -17,13 +17,17 @@
  */
 package org.apache.phoenix.end2end.index;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
@@ -32,6 +36,7 @@ import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.MetaDataUtil;
+import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.TestUtil;
 import org.junit.BeforeClass;
@@ -54,22 +59,32 @@ public class ViewIndexIT extends BaseHBaseManagedTimeIT {
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 
-    private void createBaseTable(String tableName, Integer saltBuckets, String splits) throws
SQLException {
+    private void createBaseTable(String tableName, boolean multiTenant, Integer saltBuckets,
String splits) throws SQLException {
         Connection conn = DriverManager.getConnection(getUrl());
         String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
-                "k1 INTEGER NOT NULL,\n" +
+                "k1 VARCHAR NOT NULL,\n" +
                 "k2 INTEGER NOT NULL,\n" +
                 "v1 VARCHAR,\n" +
-                "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
-                        + (saltBuckets == null || splits != null ? "" : (",salt_buckets="
+ saltBuckets)
-                        + (saltBuckets != null || splits == null ? "" : ",splits=" + splits));
-        conn.createStatement().execute(ddl);
+                "v2 INTEGER,\n" +
+                "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n";
+        String ddlOptions = multiTenant ? "MULTI_TENANT=true" : "";
+        if (saltBuckets != null) {
+            ddlOptions = ddlOptions
+                    + (ddlOptions.isEmpty() ? "" : ",")
+                    + "salt_buckets=" + saltBuckets;
+        }
+        if (splits != null) {
+            ddlOptions = ddlOptions
+                    + (ddlOptions.isEmpty() ? "" : ",")
+                    + "splits=" + splits;            
+        }
+        conn.createStatement().execute(ddl + ddlOptions);
         conn.close();
     }
 
     @Test
     public void testDeleteViewIndexSequences() throws Exception {
-        createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, null, null);
+        createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, false, null, null);
         Connection conn1 = DriverManager.getConnection(getUrl());
         Connection conn2 = DriverManager.getConnection(getUrl());
         conn1.createStatement().execute("CREATE VIEW " + VIEW_NAME + " AS SELECT * FROM "
+ TestUtil.DEFAULT_DATA_TABLE_NAME);
@@ -86,4 +101,47 @@ public class ViewIndexIT extends BaseHBaseManagedTimeIT {
                 + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE);
         assertFalse("View index sequences should be deleted.", rs.next());
     }
+    
+    @Test
+    public void testMultiTenantViewLocalIndex() throws Exception {
+        createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME, true, null, null);
+        Connection conn = DriverManager.getConnection(getUrl());
+        PreparedStatement stmt = conn.prepareStatement(
+                "UPSERT INTO " + TestUtil.DEFAULT_DATA_TABLE_NAME
+                + " VALUES(?,?,?,?,?)");
+        stmt.setString(1, "10");
+        stmt.setString(2, "a");
+        stmt.setInt(3, 1);
+        stmt.setString(4, "x1");
+        stmt.setInt(5, 100);
+        stmt.execute();
+        stmt.setString(1, "20");
+        stmt.setString(2, "b");
+        stmt.setInt(3, 2);
+        stmt.setString(4, "x2");
+        stmt.setInt(5, 200);
+        stmt.execute();
+        conn.commit();
+        conn.close();
+        
+        Properties props  = new Properties();
+        props.setProperty("TenantId", "10");
+        Connection conn1 = DriverManager.getConnection(getUrl(), props);
+        conn1.createStatement().execute("CREATE VIEW " + VIEW_NAME
+                + " AS select * from " + TestUtil.DEFAULT_DATA_TABLE_NAME);
+        conn1.createStatement().execute("CREATE LOCAL INDEX "
+                + TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON "
+                + VIEW_NAME + "(v2)");
+        conn1.commit();
+        
+        String sql = "SELECT * FROM " + VIEW_NAME + " WHERE v2 = 100";
+        ResultSet rs = conn1.prepareStatement("EXPLAIN " + sql).executeQuery();
+        assertEquals(
+                "CLIENT PARALLEL 1-WAY RANGE SCAN OVER _LOCAL_IDX_T ['10',-32768,100]\n"
+
+                "    SERVER FILTER BY FIRST KEY ONLY\n" +
+                "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+        rs = conn1.prepareStatement(sql).executeQuery();
+        assertTrue(rs.next());
+        assertFalse(rs.next());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3420a973/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index 13ad7e5..57616cb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -705,7 +705,8 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference>
{
         }
         int dataPosOffset = isDataTableSalted ? 1 : 0 ;
         if (isMultiTenant) {
-            builder.addField(dataRowKeySchema.getField(dataPosOffset++));
+            Field field = dataRowKeySchema.getField(dataPosOffset++);
+            builder.addField(field, field.isNullable(), field.getSortOrder());
             nIndexedColumns--;
         }
         if (viewIndexId != null) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3420a973/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
index a4b40f3..5c8c4f9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
@@ -318,11 +318,6 @@ public abstract class ValueSchema implements Writable {
             fields.add(new Field(datum, isNullable, 1, sortOrder));
             return this;
         }
-
-        public ValueSchemaBuilder addField(Field field) {
-            fields.add(field);
-            return this;
-        }
     }
     
     public int getEstimatedByteSize() {


Mime
View raw message