use of io.trino.sql.tree.Parameter in project trino by trinodb.
the class TestParameterExtractor method testParameterCount.
@Test
public void testParameterCount() {
Statement statement = sqlParser.createStatement("SELECT c1, c2 FROM test_table WHERE c1 = ? AND c2 > ?", new ParsingOptions());
assertThat(ParameterExtractor.getParameters(statement)).containsExactly(new Parameter(new NodeLocation(1, 41), 0), new Parameter(new NodeLocation(1, 52), 1));
assertThat(ParameterExtractor.getParameterCount(statement)).isEqualTo(2);
}
use of io.trino.sql.tree.Parameter in project trino by trinodb.
the class AstBuilder method visitParameter.
@Override
public Node visitParameter(SqlBaseParser.ParameterContext context) {
io.trino.sql.tree.Parameter parameter = new io.trino.sql.tree.Parameter(getLocation(context), parameterPosition);
parameterPosition++;
return parameter;
}
use of io.trino.sql.tree.Parameter in project trino by trinodb.
the class AstBuilder method visitQueryNoWith.
@Override
public Node visitQueryNoWith(SqlBaseParser.QueryNoWithContext context) {
QueryBody term = (QueryBody) visit(context.queryTerm());
Optional<OrderBy> orderBy = Optional.empty();
if (context.ORDER() != null) {
orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class)));
}
Optional<Offset> offset = Optional.empty();
if (context.OFFSET() != null) {
Expression rowCount;
if (context.offset.INTEGER_VALUE() != null) {
rowCount = new LongLiteral(getLocation(context.offset.INTEGER_VALUE()), context.offset.getText());
} else {
rowCount = new Parameter(getLocation(context.offset.QUESTION_MARK()), parameterPosition);
parameterPosition++;
}
offset = Optional.of(new Offset(Optional.of(getLocation(context.OFFSET())), rowCount));
}
Optional<Node> limit = Optional.empty();
if (context.FETCH() != null) {
Optional<Expression> rowCount = Optional.empty();
if (context.fetchFirst != null) {
if (context.fetchFirst.INTEGER_VALUE() != null) {
rowCount = Optional.of(new LongLiteral(getLocation(context.fetchFirst.INTEGER_VALUE()), context.fetchFirst.getText()));
} else {
rowCount = Optional.of(new Parameter(getLocation(context.fetchFirst.QUESTION_MARK()), parameterPosition));
parameterPosition++;
}
}
limit = Optional.of(new FetchFirst(Optional.of(getLocation(context.FETCH())), rowCount, context.TIES() != null));
} else if (context.LIMIT() != null) {
if (context.limit == null) {
throw new IllegalStateException("Missing LIMIT value");
}
Expression rowCount;
if (context.limit.ALL() != null) {
rowCount = new AllRows(getLocation(context.limit.ALL()));
} else if (context.limit.rowCount().INTEGER_VALUE() != null) {
rowCount = new LongLiteral(getLocation(context.limit.rowCount().INTEGER_VALUE()), context.limit.getText());
} else {
rowCount = new Parameter(getLocation(context.limit.rowCount().QUESTION_MARK()), parameterPosition);
parameterPosition++;
}
limit = Optional.of(new Limit(Optional.of(getLocation(context.LIMIT())), rowCount));
}
if (term instanceof QuerySpecification) {
// When we have a simple query specification
// followed by order by, offset, limit or fetch,
// fold the order by, limit, offset or fetch clauses
// into the query specification (analyzer/planner
// expects this structure to resolve references with respect
// to columns defined in the query specification)
QuerySpecification query = (QuerySpecification) term;
return new Query(getLocation(context), Optional.empty(), new QuerySpecification(getLocation(context), query.getSelect(), query.getFrom(), query.getWhere(), query.getGroupBy(), query.getHaving(), query.getWindows(), orderBy, offset, limit), Optional.empty(), Optional.empty(), Optional.empty());
}
return new Query(getLocation(context), Optional.empty(), term, orderBy, offset, limit);
}
use of io.trino.sql.tree.Parameter in project trino by trinodb.
the class TestParameterExtractor method testLambda.
@Test
public void testLambda() {
Statement statement = sqlParser.createStatement("SELECT * FROM test_table WHERE any_match(items, x -> x > ?)", new ParsingOptions());
assertThat(ParameterExtractor.getParameters(statement)).containsExactly(new Parameter(new NodeLocation(1, 58), 0));
assertThat(ParameterExtractor.getParameterCount(statement)).isEqualTo(1);
}
use of io.trino.sql.tree.Parameter in project trino by trinodb.
the class TableProceduresPropertyManager method getProperties.
public Map<String, Object> getProperties(CatalogName catalog, String procedureName, Map<String, Expression> sqlPropertyValues, Session session, PlannerContext plannerContext, AccessControl accessControl, Map<NodeRef<Parameter>, Expression> parameters) {
Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(new Key(catalog, procedureName));
if (supportedProperties == null) {
throw new TrinoException(NOT_FOUND, format("Catalog '%s' table procedure '%s' property not found", catalog, procedureName));
}
Map<String, Optional<Object>> propertyValues = evaluateProperties(sqlPropertyValues.entrySet().stream().map(entry -> new Property(new Identifier(entry.getKey()), entry.getValue())).collect(toImmutableList()), session, plannerContext, accessControl, parameters, true, supportedProperties, INVALID_PROCEDURE_ARGUMENT, format("catalog '%s' table procedure '%s' property", catalog, procedureName));
return propertyValues.entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));
}
Aggregations