-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR supports a Table Value Function called `Query`. He can push a query directly to the catalog source for execution by specifying `catalog` and `query` without parsing by Doris. Doris only receives the results returned by the query. Currently only JDBC Catalog is supported. Example: ``` Doris > desc function query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test'); +-------+--------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+------+---------+-------+ | cnt | BIGINT | Yes | true | NULL | NONE | +-------+--------+------+------+---------+-------+ Doris > select * from query('catalog' = 'mysql','query' = 'select count(*) as cnt from test.test'); +----------+ | cnt | +----------+ | 30000000 | +----------+ ```
- Loading branch information
Showing
12 changed files
with
432 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Query.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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.doris.nereids.trees.expressions.functions.table; | ||
|
||
import org.apache.doris.catalog.FunctionSignature; | ||
import org.apache.doris.nereids.exceptions.AnalysisException; | ||
import org.apache.doris.nereids.trees.expressions.Properties; | ||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
import org.apache.doris.nereids.types.coercion.AnyDataType; | ||
import org.apache.doris.tablefunction.QueryTableValueFunction; | ||
import org.apache.doris.tablefunction.TableValuedFunctionIf; | ||
|
||
import java.util.Map; | ||
|
||
/** query */ | ||
public class Query extends TableValuedFunction { | ||
public Query(Properties properties) { | ||
super("query", properties); | ||
} | ||
|
||
@Override | ||
public FunctionSignature customSignature() { | ||
return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, getArgumentsTypes()); | ||
} | ||
|
||
@Override | ||
protected TableValuedFunctionIf toCatalogFunction() { | ||
try { | ||
Map<String, String> arguments = getTVFProperties().getMap(); | ||
return QueryTableValueFunction.createQueryTableValueFunction(arguments); | ||
} catch (Throwable t) { | ||
throw new AnalysisException("Can not build QueryTableValuedFunction by " | ||
+ this + ": " + t.getMessage(), t); | ||
} | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitQuery(this, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
fe/fe-core/src/main/java/org/apache/doris/tablefunction/JdbcQueryTableValueFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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.doris.tablefunction; | ||
|
||
import org.apache.doris.analysis.TupleDescriptor; | ||
import org.apache.doris.catalog.Column; | ||
import org.apache.doris.catalog.JdbcTable; | ||
import org.apache.doris.catalog.TableIf.TableType; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.datasource.jdbc.JdbcExternalCatalog; | ||
import org.apache.doris.datasource.jdbc.source.JdbcScanNode; | ||
import org.apache.doris.planner.PlanNodeId; | ||
import org.apache.doris.planner.ScanNode; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class JdbcQueryTableValueFunction extends QueryTableValueFunction { | ||
public static final Logger LOG = LogManager.getLogger(JdbcQueryTableValueFunction.class); | ||
|
||
public JdbcQueryTableValueFunction(Map<String, String> params) throws AnalysisException { | ||
super(params); | ||
} | ||
|
||
@Override | ||
public List<Column> getTableColumns() throws AnalysisException { | ||
JdbcExternalCatalog catalog = (JdbcExternalCatalog) catalogIf; | ||
return catalog.getColumnsFromQuery(query); | ||
} | ||
|
||
@Override | ||
public ScanNode getScanNode(PlanNodeId id, TupleDescriptor desc) { | ||
JdbcExternalCatalog catalog = (JdbcExternalCatalog) catalogIf; | ||
JdbcTable jdbcTable = new JdbcTable(1, desc.getTable().getName(), desc.getTable().getFullSchema(), | ||
TableType.JDBC); | ||
catalog.configureJdbcTable(jdbcTable, desc.getTable().getName()); | ||
desc.setTable(jdbcTable); | ||
return new JdbcScanNode(id, desc, true, query); | ||
} | ||
} |
Oops, something went wrong.