use of com.google.zetasql.AnalyzerOptions in project beam by apache.
the class BeamZetaSqlCatalogTest method rejectsCreateFunctionStmtWithUnsupportedReturnType.
@Test
public void rejectsCreateFunctionStmtWithUnsupportedReturnType() {
JdbcConnection jdbcConnection = createJdbcConnection();
AnalyzerOptions analyzerOptions = SqlAnalyzer.baseAnalyzerOptions();
BeamZetaSqlCatalog beamCatalog = BeamZetaSqlCatalog.create(jdbcConnection.getCurrentSchemaPlus(), jdbcConnection.getTypeFactory(), analyzerOptions);
String sql = "CREATE FUNCTION foo() RETURNS ARRAY<TIME> LANGUAGE java OPTIONS (path='/does/not/exist');";
ResolvedNodes.ResolvedStatement resolvedStatement = Analyzer.analyzeStatement(sql, analyzerOptions, beamCatalog.getZetaSqlCatalog());
ResolvedNodes.ResolvedCreateFunctionStmt createFunctionStmt = (ResolvedNodes.ResolvedCreateFunctionStmt) resolvedStatement;
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("ZetaSQL type TYPE_TIME not allowed in function foo");
beamCatalog.addFunction(createFunctionStmt);
}
use of com.google.zetasql.AnalyzerOptions in project beam by apache.
the class BeamZetaSqlCatalogTest method rejectsCreateFunctionStmtWithUnsupportedParameterType.
@Test
public void rejectsCreateFunctionStmtWithUnsupportedParameterType() {
JdbcConnection jdbcConnection = createJdbcConnection();
AnalyzerOptions analyzerOptions = SqlAnalyzer.baseAnalyzerOptions();
BeamZetaSqlCatalog beamCatalog = BeamZetaSqlCatalog.create(jdbcConnection.getCurrentSchemaPlus(), jdbcConnection.getTypeFactory(), analyzerOptions);
String sql = "CREATE FUNCTION foo(a ARRAY<TIME>) RETURNS INT64 LANGUAGE java OPTIONS (path='/does/not/exist');";
ResolvedNodes.ResolvedStatement resolvedStatement = Analyzer.analyzeStatement(sql, analyzerOptions, beamCatalog.getZetaSqlCatalog());
ResolvedNodes.ResolvedCreateFunctionStmt createFunctionStmt = (ResolvedNodes.ResolvedCreateFunctionStmt) resolvedStatement;
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("ZetaSQL type TYPE_TIME not allowed in function foo");
beamCatalog.addFunction(createFunctionStmt);
}
use of com.google.zetasql.AnalyzerOptions in project beam by apache.
the class ZetaSQLPlannerImpl method rel.
public RelRoot rel(String sql, QueryParameters params) {
RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory));
AnalyzerOptions options = SqlAnalyzer.getAnalyzerOptions(params, defaultTimezone);
BeamZetaSqlCatalog catalog = BeamZetaSqlCatalog.create(defaultSchemaPlus, (JavaTypeFactory) cluster.getTypeFactory(), options);
// Set up table providers that need to be pre-registered
SqlAnalyzer analyzer = new SqlAnalyzer();
List<List<String>> tables = analyzer.extractTableNames(sql, options);
TableResolution.registerTables(this.defaultSchemaPlus, tables);
QueryTrait trait = new QueryTrait();
catalog.addTables(tables, trait);
ResolvedQueryStmt statement = analyzer.analyzeQuery(sql, options, catalog);
ExpressionConverter expressionConverter = new ExpressionConverter(cluster, params, catalog.getUserFunctionDefinitions());
ConversionContext context = ConversionContext.of(config, expressionConverter, cluster, trait);
RelNode convertedNode = QueryStatementConverter.convertRootQuery(context, statement);
return RelRoot.of(convertedNode, SqlKind.ALL);
}
use of com.google.zetasql.AnalyzerOptions in project beam by apache.
the class SqlAnalyzer method baseAnalyzerOptions.
static AnalyzerOptions baseAnalyzerOptions() {
AnalyzerOptions options = new AnalyzerOptions();
options.setErrorMessageMode(ErrorMessageMode.ERROR_MESSAGE_MULTI_LINE_WITH_CARET);
options.getLanguageOptions().setProductMode(ProductMode.PRODUCT_EXTERNAL);
options.getLanguageOptions().setEnabledLanguageFeatures(new HashSet<>(Arrays.asList(LanguageFeature.FEATURE_CREATE_AGGREGATE_FUNCTION, LanguageFeature.FEATURE_CREATE_TABLE_FUNCTION, LanguageFeature.FEATURE_DISALLOW_GROUP_BY_FLOAT, LanguageFeature.FEATURE_NUMERIC_TYPE, LanguageFeature.FEATURE_TABLE_VALUED_FUNCTIONS, LanguageFeature.FEATURE_TEMPLATE_FUNCTIONS, LanguageFeature.FEATURE_V_1_1_SELECT_STAR_EXCEPT_REPLACE, LanguageFeature.FEATURE_V_1_2_CIVIL_TIME, LanguageFeature.FEATURE_V_1_3_ADDITIONAL_STRING_FUNCTIONS)));
options.getLanguageOptions().setSupportedStatementKinds(SUPPORTED_STATEMENT_KINDS);
return options;
}
use of com.google.zetasql.AnalyzerOptions in project beam by apache.
the class SqlAnalyzer method getAnalyzerOptions.
static AnalyzerOptions getAnalyzerOptions(QueryParameters queryParams, String defaultTimezone) {
AnalyzerOptions options = baseAnalyzerOptions();
options.setDefaultTimezone(defaultTimezone);
if (queryParams.getKind() == Kind.NAMED) {
options.setParameterMode(ParameterMode.PARAMETER_NAMED);
for (Map.Entry<String, Value> entry : ((Map<String, Value>) queryParams.named()).entrySet()) {
options.addQueryParameter(entry.getKey(), entry.getValue().getType());
}
} else if (queryParams.getKind() == Kind.POSITIONAL) {
options.setParameterMode(ParameterMode.PARAMETER_POSITIONAL);
for (Value param : (List<Value>) queryParams.positional()) {
options.addPositionalQueryParameter(param.getType());
}
}
return options;
}
Aggregations