This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 9464c7f6f3 PHOENIX-7282 Incorrect data in index column for 
corresponding BIGINT type column in data table (#2001)
9464c7f6f3 is described below

commit 9464c7f6f3227956f3a99a3963b14bdb25fd2962
Author: szucsvillo <[email protected]>
AuthorDate: Mon Oct 21 16:07:01 2024 +0200

    PHOENIX-7282 Incorrect data in index column for corresponding BIGINT type 
column in data table (#2001)
---
 .../org/apache/phoenix/schema/MetaDataClient.java  |  6 ++-
 .../phoenix/end2end/AlterAddCascadeIndexIT.java    | 61 +++++++++++++++++++---
 2 files changed, 59 insertions(+), 8 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 407fce4db3..6851b6fe31 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -5019,10 +5019,12 @@ public class MetaDataClient {
                     .buildException();
         }
         indexColumn = new HashMap(indexesPTable.size());
-        PDataType indexColDataType = 
IndexUtil.getIndexColumnDataType(colDef.isNull(), colDef.getDataType());
         ColumnName
                 indexColName = 
ColumnName.caseSensitiveColumnName(IndexUtil.getIndexColumnName(familyName, 
colDef.getColumnDefName().getColumnName()));
-        ColumnDef indexColDef = FACTORY.columnDef(indexColName, 
indexColDataType.getSqlTypeName(), colDef.isNull(), colDef.getMaxLength(), 
colDef.getScale(), false, colDef.getSortOrder(), colDef.getExpression(), 
colDef.isRowTimestamp());
+        ColumnDef indexColDef = FACTORY.columnDef(indexColName,
+                colDef.getDataType().getSqlTypeName(), colDef.isNull(),
+                colDef.getMaxLength(), colDef.getScale(), false,
+                colDef.getSortOrder(), colDef.getExpression(), 
colDef.isRowTimestamp());
         // TODO: add support to specify tenant owned indexes in the DDL 
statement with CASCADE executed with Global connection
         for (PTable index : indexesPTable) {
             int iPos = indexToColumnSizeMap.get(index);
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterAddCascadeIndexIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterAddCascadeIndexIT.java
index eaf2c0009e..84aa678ee8 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterAddCascadeIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterAddCascadeIndexIT.java
@@ -30,6 +30,7 @@ import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.ColumnInfo;
 import org.apache.phoenix.util.SchemaUtil;
@@ -213,7 +214,7 @@ public class AlterAddCascadeIndexIT extends 
ParallelStatsDisabledIT {
     @Test
     public void testAlterDBOAddCascadeIndex() throws Exception {
         ColumnInfo [] columnArray =  {new ColumnInfo("new_column_1", 
PFloat.INSTANCE.getSqlType())};
-        ColumnInfo [] columnIndexArray =  {new ColumnInfo("0:new_column_1", 
PDecimal.INSTANCE.getSqlType())};
+        ColumnInfo [] columnIndexArray =  {new ColumnInfo("0:new_column_1", 
PFloat.INSTANCE.getSqlType())};
 
         String query = "ALTER " + (isViewScenario ? "VIEW " : "TABLE ")
                 + phoenixObjectName + " ADD new_column_1 FLOAT CASCADE INDEX " 
+ indexNames.split(",")[0];
@@ -234,8 +235,8 @@ public class AlterAddCascadeIndexIT extends 
ParallelStatsDisabledIT {
     public void testAlterDBOAddCascadeTwoColsOneIndex() throws Exception {
         ColumnInfo [] columnArray =  {new ColumnInfo("new_column_1", 
PFloat.INSTANCE.getSqlType()),
                 new ColumnInfo("new_column_2", PDouble.INSTANCE.getSqlType())};
-        ColumnInfo [] columnIndexArray =  {new ColumnInfo("0:new_column_1", 
PDecimal.INSTANCE.getSqlType()),
-                new ColumnInfo("0:new_column_2", 
PDecimal.INSTANCE.getSqlType())};
+        ColumnInfo [] columnIndexArray =  {new ColumnInfo("0:new_column_1", 
PFloat.INSTANCE.getSqlType()),
+                new ColumnInfo("0:new_column_2", 
PDouble.INSTANCE.getSqlType())};
         String query = "ALTER " + (isViewScenario ? "VIEW " : "TABLE ") + 
phoenixObjectName
                 + " ADD new_column_1 FLOAT, new_column_2 DOUBLE CASCADE INDEX 
" + indexNames.split(",")[0];
         conn.createStatement().execute(query);
@@ -255,7 +256,7 @@ public class AlterAddCascadeIndexIT extends 
ParallelStatsDisabledIT {
     @Test
     public void testAlterDBOAddCascadeIndexes() throws Exception {
         ColumnInfo [] columnArray = {new ColumnInfo("new_column_1", 
PDouble.INSTANCE.getSqlType())};
-        ColumnInfo [] columnIndexArray = {new ColumnInfo("0:new_column_1", 
PDecimal.INSTANCE.getSqlType())};
+        ColumnInfo [] columnIndexArray = {new ColumnInfo("0:new_column_1", 
PDouble.INSTANCE.getSqlType())};
         String query = "ALTER " + (isViewScenario ? "VIEW " : "TABLE ")
                 + phoenixObjectName + " ADD new_column_1 DOUBLE CASCADE INDEX 
" + indexNames;
         conn.createStatement().execute(query);
@@ -275,8 +276,8 @@ public class AlterAddCascadeIndexIT extends 
ParallelStatsDisabledIT {
     public void testAlterDBOAddCascadeTwoColsTwoIndexes() throws Exception {
         ColumnInfo [] columnArray =  {new ColumnInfo("new_column_1", 
PFloat.INSTANCE.getSqlType()),
                 new ColumnInfo("new_column_2", PDouble.INSTANCE.getSqlType())};
-        ColumnInfo [] columIndexArray =  {new ColumnInfo("0:new_column_1", 
PDecimal.INSTANCE.getSqlType()),
-                new ColumnInfo("0:new_column_2", 
PDecimal.INSTANCE.getSqlType())};
+        ColumnInfo [] columIndexArray =  {new ColumnInfo("0:new_column_1", 
PFloat.INSTANCE.getSqlType()),
+                new ColumnInfo("0:new_column_2", 
PDouble.INSTANCE.getSqlType())};
 
         String query = "ALTER " + (isViewScenario ? "VIEW " : "TABLE ")
                 + phoenixObjectName + " ADD new_column_1 FLOAT, new_column_2 
DOUBLE CASCADE INDEX " + indexNames;
@@ -381,6 +382,54 @@ public class AlterAddCascadeIndexIT extends 
ParallelStatsDisabledIT {
 
     }
 
+    @Test
+    public void testAlterTableCascadeIndexAllBigInt() throws Exception {
+        String schemaName = "S_"+generateUniqueName();
+        String tableName = "T_"+generateUniqueName();
+        String indexNameThree = "I_"+generateUniqueName();
+        String fullTableName = SchemaUtil.getQualifiedTableName(schemaName, 
tableName);
+        String fullIndexNameThree = 
SchemaUtil.getQualifiedTableName(schemaName, indexNameThree);
+        String createTableQuery = "CREATE TABLE " + fullTableName + " (mykey 
INTEGER NOT NULL PRIMARY KEY, col1 BIGINT)";
+        String createIndexQuery = "CREATE INDEX " + indexNameThree + " ON " + 
fullTableName + " (col1)";
+
+        conn.createStatement().execute(createTableQuery);
+        conn.createStatement().execute(createIndexQuery);
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + 
fullTableName + "(mykey, col1) VALUES(1, 2)");
+        ps.executeUpdate();
+        conn.commit();
+
+        String alterTableQuery = "ALTER TABLE " + fullTableName + " ADD IF NOT 
EXISTS col3 BIGINT CASCADE INDEX ALL";
+        conn.createStatement().execute(alterTableQuery);
+
+        PreparedStatement pss = conn.prepareStatement("UPSERT INTO " + 
fullTableName + "(mykey, col1, col3) VALUES(6, 7, 8)");
+        pss.executeUpdate();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + 
fullTableName);
+        rs.next();
+        assertEquals(1, rs.getInt(1));
+        assertEquals(2, rs.getLong(2));
+        rs.next();
+        assertEquals(6, rs.getInt(1));
+        assertEquals(7L, rs.getLong(2));
+        assertEquals(8L, rs.getLong(3));
+
+        rs = conn.createStatement().executeQuery("SELECT * FROM " + 
fullIndexNameThree);
+        rs.next();
+        assertEquals(2L, rs.getLong(1));
+        assertEquals(1, rs.getInt(2));
+        rs.next();
+        assertEquals(7L, rs.getLong(1));
+        assertEquals(6, rs.getInt(2));
+        assertEquals(8L, rs.getLong(3));
+
+        ColumnInfo[] columnArray = { new ColumnInfo("col3", 
PLong.INSTANCE.getSqlType()) };
+        ColumnInfo[] columnIndexArray = { new ColumnInfo("0:col3", 
PLong.INSTANCE.getSqlType()) };
+
+        assertDBODefinition(conn, fullTableName, PTableType.TABLE, 3, 
columnArray, false);
+        assertDBODefinition(conn, fullIndexNameThree, PTableType.INDEX, 3, 
columnIndexArray, false);
+    }
+
     private void assertDBODefinition(Connection conn, String 
phoenixObjectName, PTableType pTableType, int baseColumnCount,  ColumnInfo [] 
columnInfo, boolean fail)
             throws Exception {
         String schemaName = 
SchemaUtil.getSchemaNameFromFullName(phoenixObjectName);

Reply via email to