[BUG] Key is 'True',Extra is 'NONE' when add rollup for DUP table (#6763)

fix #6762

The result is displayed after the repair

```
mysql> desc test2 all;
+-----------+---------------+-------+---------------+------+-------+---------+-------+---------+
| IndexName | IndexKeysType | Field | Type          | Null | Key   | Default | Extra | Visible |
+-----------+---------------+-------+---------------+------+-------+---------+-------+---------+
| test2     | DUP_KEYS      | a     | BIGINT        | Yes  | true  | NULL    |       | true    |
|           |               | b     | BIGINT        | Yes  | true  | NULL    |       | true    |
|           |               | c     | BIGINT        | Yes  | false | NULL    | NONE  | true    |
|           |               | d     | BIGINT        | Yes  | false | NULL    | NONE  | true    |
|           |               | e     | VARCHAR(1024) | Yes  | false | NULL    | NONE  | true    |
|           |               | f     | VARCHAR(1024) | Yes  | false | NULL    | NONE  | true    |
|           |               |       |               |      |       |         |       |         |
| r1        | DUP_KEYS      | c     | BIGINT        | Yes  | true  | NULL    |       | true    |
|           |               | e     | VARCHAR(1024) | Yes  | true  | NULL    |       | true    |
|           |               | a     | BIGINT        | Yes  | false | NULL    | NONE  | true    |
+-----------+---------------+-------+---------------+------+-------+---------+-------+---------+

```
This commit is contained in:
shee
2021-10-16 21:54:00 +08:00
committed by GitHub
parent 607eef8d4d
commit 8baded8a0e
3 changed files with 89 additions and 1 deletions

View File

@ -201,6 +201,10 @@ public class Column implements Writable {
}
public void setIsKey(boolean isKey) {
// column is key, aggregationType is always null, isAggregationTypeImplicit is always false.
if (isKey) {
setAggregationType(null, false);
}
this.isKey = isKey;
}

View File

@ -426,4 +426,24 @@ public class RollupJobV2Test {
Assert.assertEquals("to_bitmap", resultFunctionCall.getFnName().getFunction());
}
@Test
public void testAddRollupForDupTable() throws UserException {
fakeCatalog = new FakeCatalog();
fakeEditLog = new FakeEditLog();
FakeCatalog.setCatalog(masterCatalog);
MaterializedViewHandler materializedViewHandler = Catalog.getCurrentCatalog().getRollupHandler();
Database db = masterCatalog.getDbOrDdlException(CatalogTestUtil.testDbId1);
OlapTable olapTable = (OlapTable) db.getTableOrDdlException(CatalogTestUtil.testTableId2);
AddRollupClause addRollupClause = new AddRollupClause("r1", Lists.newArrayList("k1", "v1", "v2"), null, CatalogTestUtil.testIndex2, null);
List<Column> columns = materializedViewHandler.checkAndPrepareMaterializedView(addRollupClause, olapTable, CatalogTestUtil.testIndexId2, false);
for (Column column : columns) {
if (column.nameEquals("v1", true)) {
Assert.assertNull(column.getAggregationType());
break;
}
}
}
}

View File

@ -47,12 +47,23 @@ public class CatalogTestUtil {
public static String testDb1 = "testDb1";
public static long testDbId1 = 1;
public static String testTable1 = "testTable1";
public static String testTable2 = "testTable2";
public static long testTableId1 = 2;
public static long testTableId2 = 15;
public static String testPartition1 = "testPartition1";
public static String testPartition2 = "testPartition2";
public static long testPartitionId1 = 3;
public static long testPartitionId2 = 16;
public static String testIndex1 = "testIndex1";
public static String testIndex2 = "testIndex2";
public static long testIndexId1 = 2; // the base indexId == tableId
public static long testIndexId2 = 15; // the base indexId == tableId
public static int testSchemaHash1 = 93423942;
public static long testBackendId1 = 5;
public static long testBackendId2 = 6;
@ -60,7 +71,11 @@ public class CatalogTestUtil {
public static long testReplicaId1 = 8;
public static long testReplicaId2 = 9;
public static long testReplicaId3 = 10;
public static long testReplicaId4 = 17;
public static long testTabletId1 = 11;
public static long testTabletId2 = 18;
public static long testStartVersion = 12;
public static long testStartVersionHash = 12312;
public static long testPartitionCurrentVersionHash = 12312;
@ -230,13 +245,62 @@ public class CatalogTestUtil {
// add a es table to catalog
try {
createEsTable(db);
createDupTable(db);
} catch (DdlException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
return db;
}
public static void createDupTable(Database db) {
// replica
Replica replica = new Replica(testReplicaId4, testBackendId1, testStartVersion, testStartVersionHash, 0, 0L, 0L,
ReplicaState.NORMAL, -1, 0, 0, 0);
// tablet
Tablet tablet = new Tablet(testTabletId2);
// index
MaterializedIndex index = new MaterializedIndex(testIndexId2, IndexState.NORMAL);
TabletMeta tabletMeta = new TabletMeta(testDbId1, testTableId2, testPartitionId2, testIndexId2, 0, TStorageMedium.HDD);
index.addTablet(tablet, tabletMeta);
tablet.addReplica(replica);
// partition
RandomDistributionInfo distributionInfo = new RandomDistributionInfo(1);
Partition partition = new Partition(testPartitionId2, testPartition2, index, distributionInfo);
partition.updateVisibleVersionAndVersionHash(testStartVersion, testStartVersionHash);
partition.setNextVersion(testStartVersion + 1);
partition.setNextVersionHash(testPartitionNextVersionHash, testPartitionCurrentVersionHash);
// columns
List<Column> columns = new ArrayList<Column>();
Column temp = new Column("k1", PrimitiveType.INT);
temp.setIsKey(true);
columns.add(temp);
temp = new Column("k2", PrimitiveType.INT);
temp.setIsKey(true);
columns.add(temp);
columns.add(new Column("v1", ScalarType.createType(PrimitiveType.VARCHAR), false, AggregateType.NONE, "0", ""));
columns.add(new Column("v2", ScalarType.createType(PrimitiveType.VARCHAR), false, AggregateType.NONE, "0", ""));
// table
PartitionInfo partitionInfo = new SinglePartitionInfo();
partitionInfo.setDataProperty(testPartitionId2, DataProperty.DEFAULT_DATA_PROPERTY);
partitionInfo.setReplicaAllocation(testPartitionId2, new ReplicaAllocation((short) 1));
OlapTable table = new OlapTable(testTableId2, testTable2, columns, KeysType.DUP_KEYS, partitionInfo,
distributionInfo);
table.addPartition(partition);
table.setIndexMeta(testIndexId2, testIndex2, columns, 0, testSchemaHash1, (short) 3,
TStorageType.COLUMN, KeysType.DUP_KEYS);
table.setBaseIndexId(testIndexId2);
// db
db.createTable(table);
}
public static void createEsTable(Database db) throws DdlException {
// columns
List<Column> columns = new ArrayList<>();