Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature-wip](multi-catalog)(fix) federation query failed #10602

Merged
merged 8 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove two arguments
  • Loading branch information
AshinGau committed Jul 7, 2022
commit 579bdf538ce1584911fffb6b728258e857eb4c28
12 changes: 6 additions & 6 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -4156,11 +4156,11 @@ star_expr ::=
// on IDENT [DOT]
ident:tbl DOT STAR
{:
RESULT = SelectListItem.createStarItem(new TableName(null, tbl));
RESULT = SelectListItem.createStarItem(new TableName(null, null, tbl));
:}
| ident:db DOT ident:tbl DOT STAR
{:
RESULT = SelectListItem.createStarItem(new TableName(db, tbl));
RESULT = SelectListItem.createStarItem(new TableName(null, db, tbl));
:}
| ident:ctl DOT ident:db DOT ident:tbl DOT STAR
{:
Expand All @@ -4180,9 +4180,9 @@ opt_table_name ::=

table_name ::=
ident:tbl
{: RESULT = new TableName(null, tbl); :}
{: RESULT = new TableName(null, null, tbl); :}
| ident:db DOT ident:tbl
{: RESULT = new TableName(db, tbl); :}
{: RESULT = new TableName(null, db, tbl); :}
| ident:ctl DOT ident:db DOT ident:tbl
{: RESULT = new TableName(ctl, db, tbl); :}
;
Expand Down Expand Up @@ -5311,9 +5311,9 @@ column_ref ::=
{: RESULT = new SlotRef(null, col); :}
// table_name:tblName DOT IDENT:col causes reduce/reduce conflicts
| ident:tbl DOT ident:col
{: RESULT = new SlotRef(new TableName(null, tbl), col); :}
{: RESULT = new SlotRef(new TableName(null, null, tbl), col); :}
| ident:db DOT ident:tbl DOT ident:col
{: RESULT = new SlotRef(new TableName(db, tbl), col); :}
{: RESULT = new SlotRef(new TableName(null, db, tbl), col); :}
| ident:ctl DOT ident:db DOT ident:tbl DOT ident:col
{: RESULT = new SlotRef(new TableName(ctl, db, tbl), col); :}
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public AlterTableStmt(TableName tbl, List<AlterClause> ops) {
}

public void setTableName(String newTableName) {
tbl = new TableName(tbl.getDb(), newTableName);
tbl = new TableName(tbl.getCtl(), tbl.getDb(), newTableName);
}

public TableName getTbl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public String getDbName() {
}

public void setTableName(String newTableName) {
tableName = new TableName(tableName.getDb(), newTableName);
tableName = new TableName(tableName.getCtl(), tableName.getDb(), newTableName);
}

public String getComment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void analyze(Analyzer analyzer) throws UserException {

// analyze lateral view
desc = analyzer.registerTableRef(this);
explodeSlotRef = new SlotRef(new TableName(null, viewName), columnName);
explodeSlotRef = new SlotRef(new TableName(null, null, viewName), columnName);
explodeSlotRef.analyze(analyzer);
isAnalyzed = true; // true now that we have assigned desc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ private void expandStar(Analyzer analyzer) throws AnalysisException {
if (analyzer.isSemiJoined(tableRef.getId())) {
continue;
}
expandStar(new TableName(tableRef.getAliasAsName().getDb(),
expandStar(new TableName(tableRef.getAliasAsName().getCtl(),
tableRef.getAliasAsName().getDb(),
tableRef.getAliasAsName().getTbl()),
tableRef.getDesc());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.util.Util;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.qe.ShowResultSetMetaData;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;

// SHOW COLUMNS
public class ShowColumnStmt extends ShowStmt {
private static final TableName TABLE_NAME = new TableName(InfoSchemaDb.DATABASE_NAME, "COLUMNS");
private static final TableName TABLE_NAME =
new TableName(InternalDataSource.INTERNAL_DS_NAME, InfoSchemaDb.DATABASE_NAME, "COLUMNS");
private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
.addColumn(new Column("Field", ScalarType.createVarchar(20)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.qe.ShowResultSetMetaData;

import com.google.common.collect.Lists;

// Show database statement.
public class ShowDbStmt extends ShowStmt {
private static final TableName TABLE_NAME = new TableName(InfoSchemaDb.DATABASE_NAME, "schemata");
private static final TableName TABLE_NAME =
new TableName(InternalDataSource.INTERNAL_DS_NAME, InfoSchemaDb.DATABASE_NAME, "schemata");
private static final String DB_COL = "Database";
private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ShowResultSetMetaData;
Expand All @@ -35,7 +36,8 @@

// SHOW TABLE STATUS
public class ShowTableStatusStmt extends ShowStmt {
private static final TableName TABLE_NAME = new TableName(InfoSchemaDb.DATABASE_NAME, "tables");
private static final TableName TABLE_NAME =
new TableName(InternalDataSource.INTERNAL_DS_NAME, InfoSchemaDb.DATABASE_NAME, "tables");
private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
.addColumn(new Column("Name", ScalarType.createVarchar(64)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.qe.ShowResultSetMetaData;

import com.google.common.base.Strings;
Expand All @@ -37,7 +38,8 @@ public class ShowTableStmt extends ShowStmt {
private static final String NAME_COL_PREFIX = "Tables_in_";
private static final String TYPE_COL = "Table_type";
private static final String STORAGE_FORMAT_COL = "StorageFormat";
private static final TableName TABLE_NAME = new TableName(InfoSchemaDb.DATABASE_NAME, "tables");
private static final TableName TABLE_NAME =
new TableName(InternalDataSource.INTERNAL_DS_NAME, InfoSchemaDb.DATABASE_NAME, "tables");
private String db;
private boolean isVerbose;
private String pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.InfoSchemaDb;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.qe.ShowResultSetMetaData;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -82,9 +83,11 @@ public SelectStmt toSelectStmt(Analyzer analyzer) {
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap(false);
TableName tableName = null;
if (type == SetType.GLOBAL) {
tableName = new TableName(InfoSchemaDb.DATABASE_NAME, "GLOBAL_VARIABLES");
tableName = new TableName(
InternalDataSource.INTERNAL_DS_NAME, InfoSchemaDb.DATABASE_NAME, "GLOBAL_VARIABLES");
} else {
tableName = new TableName(InfoSchemaDb.DATABASE_NAME, "SESSION_VARIABLES");
tableName = new TableName(
InternalDataSource.INTERNAL_DS_NAME, InfoSchemaDb.DATABASE_NAME, "SESSION_VARIABLES");
}
// name
SelectListItem item = new SelectListItem(new SlotRef(tableName, "VARIABLE_NAME"), NAME_COL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ private static Expr createJoinConjunct(Expr exprWithSubquery, InlineViewRef inli
return null;
}
// Create a SlotRef from the first item of inlineView's select list
SlotRef slotRef = new SlotRef(new TableName(null, inlineView.getAlias()),
SlotRef slotRef = new SlotRef(new TableName(null, null, inlineView.getAlias()),
inlineView.getColLabels().get(0));
slotRef.analyze(analyzer);
Expr subquerySubstitute = slotRef;
Expand Down
14 changes: 3 additions & 11 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ public TableName(String ctl, String db, String tbl) {
this.tbl = tbl;
}

/**
* Initialize catalog in analyze.
*/
public TableName(String db, String tbl) {
this(null, db, tbl);
}

public void analyze(Analyzer analyzer) throws AnalysisException {
if (Strings.isNullOrEmpty(ctl)) {
ctl = analyzer.getDefaultCatalog();
Expand Down Expand Up @@ -131,17 +124,16 @@ public boolean isFullyQualified() {

/**
* Analyzer.registerTableRef task alias of index 1 as the legal implicit alias.
* Cluster is deprecated, so we'd better remove cluster in external catalog, and
* keep the same in internal catalog.
*/
public String[] tableAliases() {
if (ctl == null || ctl.equals(InternalDataSource.INTERNAL_DS_NAME)) {
return new String[] {toString(), getNoClusterString(), tbl};
} else {
// Three level table aliases: ctl.db.tbl, db.tbl, tbl
return new String[] {
toString(), // with cluster name
getNoClusterString(), // without cluster name, legal implicit alias
String.format("%s.%s", db, tbl),
String.format("%s.%s", ClusterNamespace.getNameFromFullName(db), tbl),
getNoClusterString(), // legal implicit alias
tbl
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ public String getAlias() {

public TableName getAliasAsName() {
if (hasExplicitAlias()) {
return new TableName(null, getUniqueAlias());
return new TableName(null, null, getUniqueAlias());
}
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TableValuedFunctionRef extends TableRef {
private TableValuedFunctionInf tableFunction;

public TableValuedFunctionRef(String funcName, String alias, List<String> params) throws UserException {
super(new TableName(null, "_table_valued_function_" + funcName), alias);
super(new TableName(null, null, "_table_valued_function_" + funcName), alias);
this.tableFunction = TableValuedFunctionInf.getTableFunction(funcName, params);
if (hasExplicitAlias()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public String getAlias() {
}

public TableName getAliasAsName() {
return (aliases != null) ? new TableName(null, aliases[0]) : null;
return (aliases != null) ? new TableName(null, null, aliases[0]) : null;
}

public TTupleDescriptor toThrift() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private void backup(Repository repository, Database db, BackupStmt stmt) throws
tblRefs = abstractBackupTableRefClause.getTableRefList();
} else {
for (String tableName : tableNames) {
TableRef tableRef = new TableRef(new TableName(db.getFullName(), tableName), null);
TableRef tableRef = new TableRef(new TableName(null, db.getFullName(), tableName), null);
tblRefs.add(tableRef);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void handleRefreshDb(RefreshDbStmt stmt) throws DdlException {
// Current database may have other types of table, which is not allowed to drop.
for (Table table : db.getTables()) {
if (table instanceof IcebergTable) {
DropTableStmt dropTableStmt = new DropTableStmt(true, new TableName(dbName, table.getName()), true);
DropTableStmt dropTableStmt =
new DropTableStmt(true, new TableName(null, dbName, table.getName()), true);
catalog.dropTable(dropTableStmt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public PlanFragment visitPhysicalOlapScan(
tupleDescriptor.setTable(olapTable);
OlapScanNode olapScanNode = new OlapScanNode(context.nextNodeId(), tupleDescriptor, olapTable.getName());
// TODO: Do we really need tableName here?
TableName tableName = new TableName("", "");
TableName tableName = new TableName(null, "", "");
TableRef ref = new TableRef(tableName, null, null);
BaseTableRef tableRef = new BaseTableRef(ref, olapTable, tableName);
tupleDescriptor.setRef(tableRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.doris.common.FeMetaVersion;
import org.apache.doris.common.UserException;
import org.apache.doris.common.jmockit.Deencapsulation;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.meta.MetaContext;
import org.apache.doris.qe.OriginStatement;
import org.apache.doris.task.AgentTask;
Expand Down Expand Up @@ -335,7 +336,7 @@ public void testSerializeOfRollupJob(@Mocked CreateMaterializedViewStmt stmt) th
out.close();

List<Expr> params = Lists.newArrayList();
SlotRef param1 = new SlotRef(new TableName(null, "test"), "c1");
SlotRef param1 = new SlotRef(new TableName(InternalDataSource.INTERNAL_DS_NAME, null, "test"), "c1");
params.add(param1);
MVColumnItem mvColumnItem = new MVColumnItem(mvColumnName, Type.BITMAP);
mvColumnItem.setDefineExpr(new FunctionCallExpr(new FunctionName("to_bitmap"), params));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.mysql.privilege.PaloAuth;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
Expand All @@ -36,6 +37,7 @@

public class AlterTableStmtTest {
private Analyzer analyzer;
private String internalCtl = InternalDataSource.INTERNAL_DS_NAME;

@Mocked
private PaloAuth auth;
Expand Down Expand Up @@ -66,7 +68,7 @@ public void testNormal() throws UserException {
List<AlterClause> ops = Lists.newArrayList();
ops.add(new DropColumnClause("col1", "", null));
ops.add(new DropColumnClause("col2", "", null));
AlterTableStmt stmt = new AlterTableStmt(new TableName("testDb", "testTbl"), ops);
AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, "testDb", "testTbl"), ops);
stmt.analyze(analyzer);
Assert.assertEquals("ALTER TABLE `testCluster:testDb`.`testTbl` DROP COLUMN `col1`, \nDROP COLUMN `col2`",
stmt.toSql());
Expand All @@ -79,7 +81,7 @@ public void testAddRollup() throws UserException {
List<AlterClause> ops = Lists.newArrayList();
ops.add(new AddRollupClause("index1", Lists.newArrayList("col1", "col2"), null, "testTbl", null));
ops.add(new AddRollupClause("index2", Lists.newArrayList("col2", "col3"), null, "testTbl", null));
AlterTableStmt stmt = new AlterTableStmt(new TableName("testDb", "testTbl"), ops);
AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, "testDb", "testTbl"), ops);
stmt.analyze(analyzer);
Assert.assertEquals("ALTER TABLE `testCluster:testDb`.`testTbl`"
+ " ADD ROLLUP `index1` (`col1`, `col2`) FROM `testTbl`, \n"
Expand All @@ -102,7 +104,7 @@ public void testNoTable() throws UserException {
@Test(expected = AnalysisException.class)
public void testNoClause() throws UserException {
List<AlterClause> ops = Lists.newArrayList();
AlterTableStmt stmt = new AlterTableStmt(new TableName("testDb", "testTbl"), ops);
AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, "testDb", "testTbl"), ops);
stmt.analyze(analyzer);

Assert.fail("No exception throws.");
Expand All @@ -114,7 +116,7 @@ public void testEnableFeature() throws UserException {
Map<String, String> properties = Maps.newHashMap();
properties.put("function_column.sequence_type", "int");
ops.add(new EnableFeatureClause("sequence_load", properties));
AlterTableStmt stmt = new AlterTableStmt(new TableName("testDb", "testTbl"), ops);
AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, "testDb", "testTbl"), ops);
stmt.analyze(analyzer);

Assert.assertEquals("ALTER TABLE `testCluster:testDb`.`testTbl` ENABLE FEATURE \"sequence_load\" WITH PROPERTIES (\"function_column.sequence_type\" = \"int\")",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.analysis;

import org.apache.doris.catalog.Catalog;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.qe.ConnectContext;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -54,10 +55,10 @@ public BackupStmt createStmt(boolean caseSensitive) {
BackupStmt stmt;
List<TableRef> tblRefs = Lists.newArrayList();
String testDB = "test_db";
tblRefs.add(new TableRef(new TableName(null, "table1"), null));
tblRefs.add(new TableRef(new TableName(InternalDataSource.INTERNAL_DS_NAME, null, "table1"), null));
if (caseSensitive) {
// case sensitive
tblRefs.add(new TableRef(new TableName(null, "Table1"), null));
tblRefs.add(new TableRef(new TableName(InternalDataSource.INTERNAL_DS_NAME, null, "Table1"), null));
}
AbstractBackupTableRefClause tableRefClause = new AbstractBackupTableRefClause(false, tblRefs);
stmt = new BackupStmt(new LabelName(testDB, "label1"), "repo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.doris.catalog.FakeCatalog;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.datasource.InternalDataSource;
import org.apache.doris.qe.ConnectContext;

import mockit.Expectations;
Expand Down Expand Up @@ -74,14 +75,14 @@ public void testNormal() throws UserException, AnalysisException {
fakeCatalog = new FakeCatalog();
FakeCatalog.setCatalog(catalog);
// cancel alter column
CancelAlterTableStmt stmt = new CancelAlterTableStmt(AlterType.COLUMN, new TableName(null, "testTbl"));
CancelAlterTableStmt stmt = new CancelAlterTableStmt(AlterType.COLUMN, new TableName(InternalDataSource.INTERNAL_DS_NAME, null, "testTbl"));
stmt.analyze(analyzer);
Assert.assertEquals("CANCEL ALTER COLUMN FROM `testDb`.`testTbl`", stmt.toString());
Assert.assertEquals("testDb", stmt.getDbName());
Assert.assertEquals(AlterType.COLUMN, stmt.getAlterType());
Assert.assertEquals("testTbl", stmt.getTableName());

stmt = new CancelAlterTableStmt(AlterType.ROLLUP, new TableName(null, "testTbl"));
stmt = new CancelAlterTableStmt(AlterType.ROLLUP, new TableName(InternalDataSource.INTERNAL_DS_NAME, null, "testTbl"));
stmt.analyze(analyzer);
Assert.assertEquals("CANCEL ALTER ROLLUP FROM `testDb`.`testTbl`", stmt.toString());
Assert.assertEquals("testDb", stmt.getDbName());
Expand Down
Loading