You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/10/20 09:43:00 UTC

[jira] [Commented] (PHOENIX-5865) column that has default value can not be correctly indexed

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

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

stoty commented on a change in pull request #1321:
URL: https://github.com/apache/phoenix/pull/1321#discussion_r732584529



##########
File path: phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
##########
@@ -1641,9 +1641,6 @@ public MutationState createIndex(CreateIndexStatement statement, byte[][] splits
                     String columnFamilyName = column.getFamilyName()!=null ? column.getFamilyName().getString() : null;
                     colName = ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(columnFamilyName, column.getName().getString()));
                     isRowTimestamp = column.isRowTimestamp();
-                    if (colRef.getColumn().getExpressionStr() != null) {
-                        expressionStr = colRef.getColumn().getExpressionStr();

Review comment:
       I didn't dig into the default implementation.
   Is the default value resolved when upserting a row, or is it resolved when reading it back ?
   if the latter, this may break indexes for rows that have default values.

##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexWithDefaultValueIT.java
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+
+
+public class IndexWithDefaultValueIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testQueryTableWithIndex() throws Exception {
+        String tableName = generateUniqueName();
+        String indexName = generateUniqueName();
+
+        Properties props = new Properties();
+        String schema = generateUniqueName();
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+
+        conn.setSchema(schema);
+        conn.createStatement().execute("\n" +
+                "create table " + tableName + "(\n" +
+                "pk VARCHAR,\n" +
+                "b VARCHAR,\n" +
+                "c VARCHAR default '0',\n" +
+                "CONSTRAINT my_pk PRIMARY KEY (pk)\n" +
+                ")");
+
+        conn.commit();
+
+        conn.createStatement().execute("upsert into " + tableName + " values('1','1','1')");
+        conn.commit();
+
+        conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(pk, b, c)");
+        conn.commit();
+
+
+        final PreparedStatement select = conn.prepareStatement(
+                "select * from " + tableName);

Review comment:
       can you add a select here that checks if the select for the default value works when using the index ? (Unless we already have such a test elsewhere).
   Detto for the other test. 




-- 
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: issues-unsubscribe@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> column that has default value can not be correctly indexed
> ----------------------------------------------------------
>
>                 Key: PHOENIX-5865
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-5865
>             Project: Phoenix
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 5.0.0
>            Reporter: junfei liang
>            Assignee: Richárd Antal
>            Priority: Major
>         Attachments: IndexWithDefaultIT.patch
>
>
> # create a table  with a column has default value
>       create table data_table(
>  pk VARCHAR, +
> c VARCHAR default '0',
> CONSTRAINT my_pk PRIMARY KEY (pk)
>       2.  insert data into it
>        upsert into data_table values('1','1')
>       3.  create an index  on the column
>         CREATE INDEX idx_data_table ON data_table(pk, c)
>       4.  check index table ,found data is wrong
>         select * from idx_data_table
>          found  0:c  column value is '0' , but it should be 1.
>  see attachment for details.  
>  



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