[
https://issues.apache.org/jira/browse/BEAM-8592?focusedWorklogId=347597&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-347597
]
ASF GitHub Bot logged work on BEAM-8592:
----------------------------------------
Author: ASF GitHub Bot
Created on: 21/Nov/19 18:38
Start Date: 21/Nov/19 18:38
Worklog Time Spent: 10m
Work Description: apilloud commented on pull request #10021: [BEAM-8592]
Adjusting ZetaSQL table resolution to standard
URL: https://github.com/apache/beam/pull/10021#discussion_r349251079
##########
File path:
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/TableResolution.java
##########
@@ -19,43 +19,60 @@
import com.google.zetasql.SimpleTable;
import java.util.List;
-import org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.plan.Context;
+import java.util.stream.Collectors;
+import org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema;
+import org.apache.beam.sdk.extensions.sql.impl.TableName;
+import org.apache.beam.sdk.extensions.sql.meta.CustomTableResolver;
+import
org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.schema.Schema;
import
org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.schema.SchemaPlus;
import org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.schema.Table;
import
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables;
/** Utility methods to resolve a table, given a top-level Calcite schema and a
table path. */
public class TableResolution {
- /**
- * Returns Calcite Table by consulting the schema.
- *
- * <p>The way the schema is queried is defined by the name resolution
strategey implemented by a
- * TableResolver and stored as a TableResolutionContext in the context.
- *
- * <p>If no custom table resolution logic is provided, default one is used,
which is: drill down
- * the getSubschema() path until the second-to-last path element. We expect
the path to be a table
- * path, so the last element should be a valid table id, we don't expect
anything else there.
- *
- * <p>This resembles a default Calcite planner strategy. One difference is
that Calcite doesn't
- * assume the last element is a table and will continue to call
getSubschema(), making it
- * impossible for a table provider to understand the context.
- */
- public static Table resolveCalciteTable(
- Context context, SchemaPlus schemaPlus, List<String> tablePath) {
- TableResolutionContext tableResolutionContext =
context.unwrap(TableResolutionContext.class);
- TableResolver tableResolver = getTableResolver(tableResolutionContext,
schemaPlus.getName());
- return tableResolver.resolveCalciteTable(schemaPlus, tablePath);
+ /** Returns Calcite Table by consulting the schema. */
+ public static Table resolveCalciteTable(SchemaPlus schemaPlus, List<String>
tablePath) {
+ Schema subSchema = schemaPlus;
+
+ // subSchema.getSubschema() for all except last
+ for (int i = 0; i < tablePath.size() - 1; i++) {
+ subSchema = subSchema.getSubSchema(tablePath.get(i));
+ if (subSchema == null) {
+ throw new IllegalStateException(
+ String.format(
+ "While resolving table path %s, no sub-schema found for
component %s (\"%s\")",
+ tablePath, i, tablePath.get(i)));
+ }
+ }
+
+ // for the final one call getTable()
+ return subSchema.getTable(Iterables.getLast(tablePath));
}
- static TableResolver getTableResolver(
- TableResolutionContext tableResolutionContext, String schemaName) {
- if (tableResolutionContext == null
- || !tableResolutionContext.hasCustomResolutionFor(schemaName)) {
- return TableResolver.DEFAULT_ASSUME_LEAF_IS_TABLE;
+ // Set up table providers that need to be pre-registered
+ // TODO: share this logic between dialects, set up tables on JDBC connection
too
+
Review comment:
nit:Extra whitespace?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 347597)
Time Spent: 1.5h (was: 1h 20m)
> DataCatalogTableProvider should not squash table components together into a
> string
> ----------------------------------------------------------------------------------
>
> Key: BEAM-8592
> URL: https://issues.apache.org/jira/browse/BEAM-8592
> Project: Beam
> Issue Type: Bug
> Components: dsl-sql, dsl-sql-zetasql
> Reporter: Kenneth Knowles
> Assignee: Kenneth Knowles
> Priority: Major
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> Currently, if a user writes a table name like \{{foo.`baz.bar`.bizzle}}
> representing the components \{{"foo", "baz.bar", "bizzle"}} the
> DataCatalogTableProvider will concatenate the components into a string and
> resolve the identifier as if it represented \{{"foo", "baz", "bar",
> "bizzle"}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)