use of io.trino.sql.tree.PatternSearchMode in project trino by trinodb.
the class AstBuilder method visitPatternRecognition.
@Override
public Node visitPatternRecognition(SqlBaseParser.PatternRecognitionContext context) {
Relation child = (Relation) visit(context.aliasedRelation());
if (context.MATCH_RECOGNIZE() == null) {
return child;
}
Optional<OrderBy> orderBy = Optional.empty();
if (context.ORDER() != null) {
orderBy = Optional.of(new OrderBy(getLocation(context.ORDER()), visit(context.sortItem(), SortItem.class)));
}
Optional<PatternSearchMode> searchMode = Optional.empty();
if (context.INITIAL() != null) {
searchMode = Optional.of(new PatternSearchMode(getLocation(context.INITIAL()), INITIAL));
} else if (context.SEEK() != null) {
searchMode = Optional.of(new PatternSearchMode(getLocation(context.SEEK()), SEEK));
}
PatternRecognitionRelation relation = new PatternRecognitionRelation(getLocation(context), child, visit(context.partition, Expression.class), orderBy, visit(context.measureDefinition(), MeasureDefinition.class), getRowsPerMatch(context.rowsPerMatch()), visitIfPresent(context.skipTo(), SkipTo.class), searchMode, (RowPattern) visit(context.rowPattern()), visit(context.subsetDefinition(), SubsetDefinition.class), visit(context.variableDefinition(), VariableDefinition.class));
if (context.identifier() == null) {
return relation;
}
List<Identifier> aliases = null;
if (context.columnAliases() != null) {
aliases = visit(context.columnAliases().identifier(), Identifier.class);
}
return new AliasedRelation(getLocation(context), relation, (Identifier) visit(context.identifier()), aliases);
}
Aggregations