This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new d831322806 [refactor](planner): make Table abstract. (#11642) d831322806 is described below commit d831322806cbd4ddccf325aac037670367a79555 Author: jakevin <jakevin...@gmail.com> AuthorDate: Thu Aug 11 12:07:25 2022 +0800 [refactor](planner): make Table abstract. (#11642) --- .../main/java/org/apache/doris/catalog/Table.java | 2 +- .../java/org/apache/doris/catalog/FakeEnv.java | 1 - .../java/org/apache/doris/catalog/TableTest.java | 44 ++++++++++++++------ .../doris/common/util/MetaLockUtilsTest.java | 47 +++++++++------------- .../doris/nereids/jobs/RewriteTopDownJobTest.java | 4 +- .../apache/doris/nereids/util/PlanConstructor.java | 17 ++------ .../doris/planner/RuntimeFilterGeneratorTest.java | 15 ++++--- 7 files changed, 65 insertions(+), 65 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java index c7fdfce7fd..eea6dce796 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java @@ -49,7 +49,7 @@ import java.util.stream.Collectors; /** * Internal representation of table-related metadata. A table contains several partitions. */ -public class Table extends MetaObject implements Writable, TableIf { +public abstract class Table extends MetaObject implements Writable, TableIf { private static final Logger LOG = LogManager.getLogger(Table.class); // empirical value. diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/FakeEnv.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/FakeEnv.java index e94a32f113..32f32cf9e7 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/FakeEnv.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/FakeEnv.java @@ -42,7 +42,6 @@ public class FakeEnv extends MockUp<Env> { @Mock public static Env getCurrentEnv() { - System.out.println("fake get current env is called"); return env; } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/TableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/TableTest.java index 3a04d6d8cf..df36c50973 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/TableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/TableTest.java @@ -25,6 +25,7 @@ import org.apache.doris.common.MetaNotFoundException; import org.apache.doris.common.jmockit.Deencapsulation; import org.apache.doris.thrift.TStorageType; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Before; @@ -40,19 +41,38 @@ import java.util.List; import java.util.concurrent.TimeUnit; public class TableTest { - private FakeEnv fakeEnv; - private Env env; + public static OlapTable newOlapTable(long tableId, String tableName, int hashColumn) { + List<Column> columns = ImmutableList.of( + new Column("id", Type.INT, true, AggregateType.NONE, "0", "")); + + return newOlapTable(tableId, tableName, hashColumn, columns); + } + + public static OlapTable newOlapTable(long tableId, String tableName, int hashColumn, List<Column> columns) { + HashDistributionInfo hashDistributionInfo = new HashDistributionInfo(3, + ImmutableList.of(columns.get(hashColumn))); + + OlapTable table = new OlapTable(tableId, tableName, columns, + KeysType.PRIMARY_KEYS, null, hashDistributionInfo); + table.setIndexMeta(-1, + "base", + table.getFullSchema(), + 0, 0, (short) 0, + TStorageType.COLUMN, + KeysType.PRIMARY_KEYS); + return table; + } + + private FakeEnv fakeEnv; private Table table; - private long tableId = 10000; @Before public void setUp() { + table = newOlapTable(10000, "test", 0); fakeEnv = new FakeEnv(); - env = Deencapsulation.newInstance(Env.class); - table = new Table(Table.TableType.OLAP); - table.setName("test"); + Env env = Deencapsulation.newInstance(Env.class); FakeEnv.setEnv(env); FakeEnv.setMetaVersion(FeConstants.meta_version); } @@ -118,22 +138,22 @@ public class TableTest { ScalarType.createType(PrimitiveType.TINYINT), false, AggregateType.MIN, "", ""); columns.add(column2); columns.add(new Column("column3", - ScalarType.createType(PrimitiveType.SMALLINT), false, AggregateType.SUM, "", "")); + ScalarType.createType(PrimitiveType.SMALLINT), false, AggregateType.SUM, "", "")); columns.add(new Column("column4", - ScalarType.createType(PrimitiveType.INT), false, AggregateType.REPLACE, "", "")); + ScalarType.createType(PrimitiveType.INT), false, AggregateType.REPLACE, "", "")); columns.add(new Column("column5", - ScalarType.createType(PrimitiveType.BIGINT), false, AggregateType.REPLACE, "", "")); + ScalarType.createType(PrimitiveType.BIGINT), false, AggregateType.REPLACE, "", "")); columns.add(new Column("column6", - ScalarType.createType(PrimitiveType.FLOAT), false, AggregateType.REPLACE, "", "")); + ScalarType.createType(PrimitiveType.FLOAT), false, AggregateType.REPLACE, "", "")); columns.add(new Column("column7", - ScalarType.createType(PrimitiveType.DOUBLE), false, AggregateType.REPLACE, "", "")); + ScalarType.createType(PrimitiveType.DOUBLE), false, AggregateType.REPLACE, "", "")); columns.add(new Column("column8", ScalarType.createChar(10), true, null, "", "")); columns.add(new Column("column9", ScalarType.createVarchar(10), true, null, "", "")); columns.add(new Column("column10", ScalarType.createType(PrimitiveType.DATE), true, null, "", "")); columns.add(new Column("column11", ScalarType.createType(PrimitiveType.DATETIME), true, null, "", "")); OlapTable table1 = new OlapTable(1000L, "group1", columns, KeysType.AGG_KEYS, - new SinglePartitionInfo(), new RandomDistributionInfo(10)); + new SinglePartitionInfo(), new RandomDistributionInfo(10)); short shortKeyColumnCount = 1; table1.setIndexMeta(1000, "group1", columns, 1, 1, shortKeyColumnCount, TStorageType.COLUMN, KeysType.AGG_KEYS); diff --git a/fe/fe-core/src/test/java/org/apache/doris/common/util/MetaLockUtilsTest.java b/fe/fe-core/src/test/java/org/apache/doris/common/util/MetaLockUtilsTest.java index 026d93dc15..1669038913 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/common/util/MetaLockUtilsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/MetaLockUtilsTest.java @@ -19,8 +19,10 @@ package org.apache.doris.common.util; import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Table; +import org.apache.doris.catalog.TableTest; import org.apache.doris.common.MetaNotFoundException; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Rule; @@ -32,6 +34,9 @@ import java.util.concurrent.TimeUnit; public class MetaLockUtilsTest { + List<Table> tableList = ImmutableList.of(TableTest.newOlapTable(0, "test1", 0), + TableTest.newOlapTable(1, "test2", 0)); + @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -50,7 +55,6 @@ public class MetaLockUtilsTest { @Test public void testReadLockTables() { - List<Table> tableList = Lists.newArrayList(new Table(Table.TableType.OLAP), new Table(Table.TableType.OLAP)); MetaLockUtils.readLockTables(tableList); Assert.assertFalse(tableList.get(0).tryWriteLock(1, TimeUnit.MILLISECONDS)); Assert.assertFalse(tableList.get(1).tryWriteLock(1, TimeUnit.MILLISECONDS)); @@ -63,7 +67,6 @@ public class MetaLockUtilsTest { @Test public void testWriteLockTables() throws MetaNotFoundException { - List<Table> tableList = Lists.newArrayList(new Table(Table.TableType.OLAP), new Table(Table.TableType.OLAP)); MetaLockUtils.writeLockTables(tableList); Assert.assertTrue(tableList.get(0).isWriteLockHeldByCurrentThread()); Assert.assertTrue(tableList.get(1).isWriteLockHeldByCurrentThread()); @@ -83,51 +86,39 @@ public class MetaLockUtilsTest { @Test public void testWriteLockTablesWithMetaNotFoundException() throws MetaNotFoundException { - List<Table> tableList = Lists.newArrayList(); - Table table1 = new Table(Table.TableType.OLAP); - Table table2 = new Table(Table.TableType.OLAP); - table2.setName("test2"); - tableList.add(table1); - tableList.add(table2); MetaLockUtils.writeLockTablesOrMetaException(tableList); - Assert.assertTrue(table1.isWriteLockHeldByCurrentThread()); - Assert.assertTrue(table2.isWriteLockHeldByCurrentThread()); + Assert.assertTrue(tableList.get(0).isWriteLockHeldByCurrentThread()); + Assert.assertTrue(tableList.get(1).isWriteLockHeldByCurrentThread()); MetaLockUtils.writeUnlockTables(tableList); - Assert.assertFalse(table1.isWriteLockHeldByCurrentThread()); - Assert.assertFalse(table2.isWriteLockHeldByCurrentThread()); - table2.markDropped(); + Assert.assertFalse(tableList.get(0).isWriteLockHeldByCurrentThread()); + Assert.assertFalse(tableList.get(1).isWriteLockHeldByCurrentThread()); + tableList.get(1).markDropped(); expectedException.expect(MetaNotFoundException.class); expectedException.expectMessage("errCode = 7, detailMessage = unknown table, tableName=test2"); try { MetaLockUtils.writeLockTablesOrMetaException(tableList); } finally { - Assert.assertFalse(table1.isWriteLockHeldByCurrentThread()); - Assert.assertFalse(table2.isWriteLockHeldByCurrentThread()); + Assert.assertFalse(tableList.get(0).isWriteLockHeldByCurrentThread()); + Assert.assertFalse(tableList.get(1).isWriteLockHeldByCurrentThread()); } } @Test public void testTryWriteLockTablesWithMetaNotFoundException() throws MetaNotFoundException { - List<Table> tableList = Lists.newArrayList(); - Table table1 = new Table(Table.TableType.OLAP); - Table table2 = new Table(Table.TableType.OLAP); - table2.setName("test2"); - tableList.add(table1); - tableList.add(table2); MetaLockUtils.tryWriteLockTablesOrMetaException(tableList, 1000, TimeUnit.MILLISECONDS); - Assert.assertTrue(table1.isWriteLockHeldByCurrentThread()); - Assert.assertTrue(table2.isWriteLockHeldByCurrentThread()); + Assert.assertTrue(tableList.get(0).isWriteLockHeldByCurrentThread()); + Assert.assertTrue(tableList.get(1).isWriteLockHeldByCurrentThread()); MetaLockUtils.writeUnlockTables(tableList); - Assert.assertFalse(table1.isWriteLockHeldByCurrentThread()); - Assert.assertFalse(table2.isWriteLockHeldByCurrentThread()); - table2.markDropped(); + Assert.assertFalse(tableList.get(0).isWriteLockHeldByCurrentThread()); + Assert.assertFalse(tableList.get(1).isWriteLockHeldByCurrentThread()); + tableList.get(1).markDropped(); expectedException.expect(MetaNotFoundException.class); expectedException.expectMessage("errCode = 7, detailMessage = unknown table, tableName=test2"); try { MetaLockUtils.tryWriteLockTablesOrMetaException(tableList, 1000, TimeUnit.MILLISECONDS); } finally { - Assert.assertFalse(table1.isWriteLockHeldByCurrentThread()); - Assert.assertFalse(table2.isWriteLockHeldByCurrentThread()); + Assert.assertFalse(tableList.get(0).isWriteLockHeldByCurrentThread()); + Assert.assertFalse(tableList.get(1).isWriteLockHeldByCurrentThread()); } } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java index 0e63db22a1..5aa19b65e2 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java @@ -51,7 +51,7 @@ public class RewriteTopDownJobTest { @Override public Rule build() { return unboundRelation().then(unboundRelation -> - new LogicalBoundRelation(PlanConstructor.newTable(0L, "test"), Lists.newArrayList("test")) + new LogicalBoundRelation(PlanConstructor.newOlapTable(0L, "test", 0), Lists.newArrayList("test")) ).toRule(RuleType.BINDING_RELATION); } } @@ -59,7 +59,7 @@ public class RewriteTopDownJobTest { @Test public void testSimplestScene() { Plan leaf = new UnboundRelation(Lists.newArrayList("test")); - LogicalProject project = new LogicalProject(ImmutableList.of( + LogicalProject<Plan> project = new LogicalProject<>(ImmutableList.of( new SlotReference("name", StringType.INSTANCE, true, ImmutableList.of("test"))), leaf ); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/PlanConstructor.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/PlanConstructor.java index e8b7c193aa..34b319bb1e 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/PlanConstructor.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/PlanConstructor.java @@ -22,7 +22,6 @@ import org.apache.doris.catalog.Column; import org.apache.doris.catalog.HashDistributionInfo; import org.apache.doris.catalog.KeysType; import org.apache.doris.catalog.OlapTable; -import org.apache.doris.catalog.Table; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan; import org.apache.doris.thrift.TStorageType; @@ -59,15 +58,15 @@ public class PlanConstructor { 0, 0, (short) 0, TStorageType.COLUMN, KeysType.PRIMARY_KEYS); - course.setIndexMeta(-1, + score.setIndexMeta(-1, "base", - course.getFullSchema(), + score.getFullSchema(), 0, 0, (short) 0, TStorageType.COLUMN, KeysType.PRIMARY_KEYS); - score.setIndexMeta(-1, + course.setIndexMeta(-1, "base", - score.getFullSchema(), + course.getFullSchema(), 0, 0, (short) 0, TStorageType.COLUMN, KeysType.PRIMARY_KEYS); @@ -92,14 +91,6 @@ public class PlanConstructor { return table; } - public static Table newTable(long tableId, String tableName) { - return new Table(tableId, tableName, Table.TableType.OLAP, - ImmutableList.<Column>of( - new Column("id", Type.INT, true, AggregateType.NONE, "0", ""), - new Column("name", Type.STRING, true, AggregateType.NONE, "", "") - )); - } - // With OlapTable. // Warning: equals() of Table depends on tableId. public static LogicalOlapScan newLogicalOlapScan(long tableId, String tableName, int hashColumn) { diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/RuntimeFilterGeneratorTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/RuntimeFilterGeneratorTest.java index 70835d708a..de23f74249 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/RuntimeFilterGeneratorTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/RuntimeFilterGeneratorTest.java @@ -31,15 +31,16 @@ import org.apache.doris.analysis.TupleDescriptor; import org.apache.doris.analysis.TupleId; import org.apache.doris.catalog.Column; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.PrimitiveType; -import org.apache.doris.catalog.Table; +import org.apache.doris.catalog.TableTest; import org.apache.doris.common.UserException; import org.apache.doris.common.jmockit.Deencapsulation; import org.apache.doris.datasource.InternalDataSource; import org.apache.doris.qe.ConnectContext; import org.apache.doris.thrift.TPartitionType; -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableList; import mockit.Expectations; import mockit.Mocked; import org.junit.Assert; @@ -76,12 +77,11 @@ public class RuntimeFilterGeneratorTest { TableName lhsTableName = new TableName(InternalDataSource.INTERNAL_DS_NAME, "default_cluster:test_db", "test_lhs_tbl"); SlotRef lhsExpr = new SlotRef(lhsTableName, "test_lhs_col"); SlotDescriptor lhsSlotDescriptor = new SlotDescriptor(new SlotId(0), lhsTupleDescriptor); - Column k1 = new Column("test_lhs_col", PrimitiveType.BIGINT); + Column k1 = new Column("test_lhs_col", PrimitiveType.BIGINT, false); k1.setIsKey(true); - k1.setIsAllowNull(false); lhsSlotDescriptor.setColumn(k1); lhsExpr.setDesc(lhsSlotDescriptor); - Table lhsTable = new Table(0, "test_lhs_tbl", Table.TableType.OLAP, Lists.newArrayList(k1)); + OlapTable lhsTable = TableTest.newOlapTable(0, "test_lhs_tbl", 0, ImmutableList.of(k1)); BaseTableRef lhsTableRef = new BaseTableRef(tableRef, lhsTable, lhsTableName); lhsTableRef.analyze(analyzer); @@ -90,12 +90,11 @@ public class RuntimeFilterGeneratorTest { TableName rhsTableName = new TableName(InternalDataSource.INTERNAL_DS_NAME, "default_cluster:test_db", "test_rhs_tbl"); SlotRef rhsExpr = new SlotRef(rhsTableName, "test_rhs_col"); SlotDescriptor rhsSlotDescriptor = new SlotDescriptor(new SlotId(1), rhsTupleDescriptor); - Column k2 = new Column("test_rhs_col", PrimitiveType.INT); + Column k2 = new Column("test_rhs_col", PrimitiveType.INT, false); k2.setIsKey(true); - k2.setIsAllowNull(false); rhsSlotDescriptor.setColumn(k2); rhsExpr.setDesc(rhsSlotDescriptor); - Table rhsTable = new Table(0, "test_rhs_tbl", Table.TableType.OLAP, Lists.newArrayList(k2)); + OlapTable rhsTable = TableTest.newOlapTable(0, "test_rhs_tbl", 0, ImmutableList.of(k2)); BaseTableRef rhsTableRef = new BaseTableRef(tableRef, rhsTable, rhsTableName); rhsTableRef.analyze(analyzer); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org