[ 
https://issues.apache.org/jira/browse/PHOENIX-5712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17238480#comment-17238480
 ] 

ASF GitHub Bot commented on PHOENIX-5712:
-----------------------------------------

yanxinyi commented on a change in pull request #972:
URL: https://github.com/apache/phoenix/pull/972#discussion_r530083783



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIndexIdRetrieveIT.java
##########
@@ -0,0 +1,169 @@
+/*
+ * 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 static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID;
+import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE;
+import static 
org.apache.phoenix.query.QueryServices.LONG_VIEW_INDEX_ENABLED_ATTRIB;
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.Map;
+import java.util.Properties;
+
+import com.google.common.collect.Maps;
+import org.apache.hadoop.hbase.regionserver.ScanInfoUtil;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ViewIndexIdRetrieveIT extends ParallelStatsDisabledIT {
+    private String ddlForBaseTable = "CREATE TABLE %s (TENANT_ID CHAR(15) NOT 
NULL, ID CHAR(3)" +
+            " NOT NULL, NUM BIGINT CONSTRAINT PK PRIMARY KEY (TENANT_ID, ID))" 
+
+            " MULTI_TENANT = true, COLUMN_ENCODED_BYTES=0 ";
+    private String ddlForView = "CREATE VIEW %s (A BIGINT PRIMARY KEY, B 
BIGINT)" +
+            " AS SELECT * FROM %s WHERE ID='ABC'";
+    private String ddlForViewIndex =
+            "CREATE INDEX %s ON %s (B DESC) INCLUDE (NUM)";
+    private String selectAll = "SELECT * FROM SYSTEM.CATALOG";
+    private String selectRow = "SELECT VIEW_INDEX_ID,VIEW_INDEX_ID_DATA_TYPE" +
+            " FROM SYSTEM.CATALOG WHERE TABLE_NAME='%s' AND COLUMN_COUNT IS 
NOT NULL";
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+        props.put(ScanInfoUtil.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY, 
Integer.toString(60*60));
+        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    }
+
+    @Test
+    public void testSelectViewIndexIdAsLong() throws Exception {
+        testSelectViewIndexId(true);
+    }
+
+    @Test
+    public void testSelectViewIndexIdAsShort() throws Exception {
+        testSelectViewIndexId(false);
+    }
+
+    private void testSelectViewIndexId(boolean isTestingLongViewIndexId) 
throws Exception {
+        String val = isTestingLongViewIndexId ? "true" : "false";
+        int expectedDataType = isTestingLongViewIndexId ? Types.BIGINT : 
Types.SMALLINT;
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, val);
+        String schema = generateUniqueName();
+        String baseTable = generateUniqueName();
+        String fullTableName = SchemaUtil.getTableName(schema, baseTable);
+        String viewName = generateUniqueName();
+        String viewFullName = SchemaUtil.getTableName(schema, viewName);
+        String viewIndexName = generateUniqueName();
+        try (final Connection conn = DriverManager.getConnection(url,props);
+             final Statement stmt = conn.createStatement()) {
+            stmt.execute(String.format(ddlForBaseTable, fullTableName));
+            stmt.execute(String.format(ddlForView, viewFullName, 
fullTableName));
+            stmt.execute(String.format(ddlForViewIndex, viewIndexName, 
viewFullName));
+
+            ResultSet rs = stmt.executeQuery(String.format(selectRow, 
viewIndexName));
+            rs.next();
+            assertEquals(Short.MIN_VALUE,rs.getLong(1));
+            assertEquals(expectedDataType, rs.getInt(2));
+            assertFalse(rs.next());
+        }
+    }
+
+    @Test
+    public void testMixedCase() throws Exception {
+        // mixed case
+        Properties propsForLongType = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        propsForLongType.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, "true");
+        String schema = generateUniqueName();
+        String baseTable = generateUniqueName();
+        String fullTableName = SchemaUtil.getTableName(schema, baseTable);
+        String viewName = generateUniqueName();
+        String viewFullName = SchemaUtil.getTableName(schema, viewName);
+        String viewIndexName1 = generateUniqueName();
+
+        // view index id data type is long
+        try (final Connection conn = 
DriverManager.getConnection(url,propsForLongType);
+             final Statement stmt = conn.createStatement()) {
+            stmt.execute(String.format(ddlForBaseTable, fullTableName));
+            stmt.execute(String.format(ddlForView, viewFullName, 
fullTableName));
+            stmt.execute(String.format(ddlForViewIndex, viewIndexName1, 
viewFullName));
+
+            ResultSet rs = stmt.executeQuery(String.format(selectRow, 
viewIndexName1));
+            rs.next();
+            assertEquals(Short.MIN_VALUE,rs.getLong(1));
+            assertEquals(Types.BIGINT, rs.getInt(2));
+            assertFalse(rs.next());
+        }
+
+        // view index id data type is short
+        String viewIndexName2 = generateUniqueName();
+        Properties propsForShortType = 
PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        propsForShortType.setProperty(LONG_VIEW_INDEX_ENABLED_ATTRIB, "false");
+        try (final Connection conn = 
DriverManager.getConnection(url,propsForShortType);
+             final Statement stmt = conn.createStatement()) {
+            stmt.execute(String.format(ddlForViewIndex, viewIndexName2, 
viewFullName));
+
+            ResultSet rs = stmt.executeQuery(String.format(selectRow, 
viewIndexName2));
+            rs.next();
+            assertEquals(Short.MIN_VALUE + 1,rs.getLong(1));
+            assertEquals(Types.SMALLINT, rs.getInt(2));
+            assertFalse(rs.next());
+        }
+
+        // check select * from syscat
+        try (final Connection conn = DriverManager.getConnection(url);
+             final Statement stmt = conn.createStatement()) {
+            ResultSet rs = stmt.executeQuery(String.format(selectAll));

Review comment:
       because we want to test the mixed cases.
   in this test, we create two views (one with smallint config, and one with 
bigint config)




----------------------------------------------------------------
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:
[email protected]


> Got SYSCAT  ILLEGAL_DATA exception after created tenant index on view
> ---------------------------------------------------------------------
>
>                 Key: PHOENIX-5712
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-5712
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.15.0
>            Reporter: Xinyi Yan
>            Assignee: Xinyi Yan
>            Priority: Blocker
>             Fix For: 5.1.0, 4.16.0
>
>         Attachments: 5712-WIP.txt, 5712-test.txt, PHOENIX-5712.4.x.v1.patch, 
> PHOENIX-5712.patch, Screen Shot 2020-09-21 at 10.13.17 PM.png, Screen Shot 
> 2020-09-21 at 10.18.08 PM.png, t.txt
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> repo
> //create a multi-tenant table on global connection
> CREATE TABLE A (TENANT_ID CHAR(15) NOT NULL, ID CHAR(3) NOT NULL, NUM BIGINT 
> CONSTRAINT PK PRIMARY KEY (TENANT_ID, ID)) MULTI_TENANT = true;
> // create view and index on tenant connection
> CREATE VIEW A_VIEW AS SELECT * FROM A;
> UPSERT INTO A_VIEW (ID, NUM) VALUES ('A', 1);
> CREATE INDEX A_VIEW_INDEX ON A_VIEW (NUM DESC) INCLUDE (ID);
> // qeury data on global connection 
> SELECT * RFOM SYSTEM.CATALOG;
> {code:java}
> Error: ERROR 201 (22000): Illegal data. Expected length of at least 8 bytes, 
> but had 3 (state=22000,code=201)
> java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length of at 
> least 8 bytes, but had 3
>         at 
> org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:559)
>         at 
> org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:195)
>         at 
> org.apache.phoenix.schema.types.PDataType.checkForSufficientLength(PDataType.java:290)
>         at 
> org.apache.phoenix.schema.types.PLong$LongCodec.decodeLong(PLong.java:256)
>         at org.apache.phoenix.schema.types.PLong.toObject(PLong.java:115)
>         at org.apache.phoenix.schema.types.PLong.toObject(PLong.java:31)
>         at 
> org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:1011)
>         at 
> org.apache.phoenix.compile.ExpressionProjector.getValue(ExpressionProjector.java:75)
>         at 
> org.apache.phoenix.jdbc.PhoenixResultSet.getObject(PhoenixResultSet.java:585)
>         at sqlline.Rows$Row.<init>(Rows.java:258)
>         at sqlline.BufferedRows.nextList(BufferedRows.java:111)
>         at sqlline.BufferedRows.<init>(BufferedRows.java:52)
>         at sqlline.SqlLine.print(SqlLine.java:1623)
>         at sqlline.Commands.execute(Commands.java:982)
>         at sqlline.Commands.sql(Commands.java:906)
>         at sqlline.SqlLine.dispatch(SqlLine.java:740)
>         at sqlline.SqlLine.begin(SqlLine.java:557)
>         at sqlline.SqlLine.start(SqlLine.java:270)
>         at sqlline.SqlLine.main(SqlLine.java:201)
> {code}
> I tried to drop the view, and I was able to query the data from the SYSCATA. 
> I tested on 4.x-HBase1.3 and master branch, all branches have the same 
> behavior.
>  
> cc [~kadir] [~gjacoby] [~swaroopa]
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to