@Override public Node visitTypeConstructor(SqlBaseParser.TypeConstructorContext context) { String value = ((StringLiteral) visit(context.string())).getValue(); if (context.DOUBLE_PRECISION() != null) { // TODO: Temporary hack that should be removed with new planner. return new GenericLiteral(getLocation(context), "DOUBLE", value); } String type = context.identifier().getText(); if (type.equalsIgnoreCase("time")) { return new TimeLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("timestamp")) { return new TimestampLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("decimal")) { return new DecimalLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("char")) { return new CharLiteral(getLocation(context), value); } return new GenericLiteral(getLocation(context), type, value); }
@Override public Node visitExtract(SqlBaseParser.ExtractContext context) { String fieldString = context.identifier().getText(); Extract.Field field; try { field = Extract.Field.valueOf(fieldString.toUpperCase()); } catch (IllegalArgumentException e) { throw parseError("Invalid EXTRACT field: " + fieldString, context); } return new Extract(getLocation(context), (Expression) visit(context.valueExpression()), field); }
private Map<String, Expression> processTableProperties(TablePropertiesContext tablePropertiesContext) { ImmutableMap.Builder<String, Expression> properties = ImmutableMap.builder(); if (tablePropertiesContext != null) { for (TablePropertyContext tablePropertyContext : tablePropertiesContext.tableProperty()) { properties.put(tablePropertyContext.identifier().getText(), (Expression) visit(tablePropertyContext.expression())); } } return properties.build(); }
@Override public Node visitTypeConstructor(SqlBaseParser.TypeConstructorContext context) { String value = ((StringLiteral) visit(context.string())).getValue(); if (context.DOUBLE_PRECISION() != null) { // TODO: Temporary hack that should be removed with new planner. return new GenericLiteral(getLocation(context), "DOUBLE", value); } String type = context.identifier().getText(); if (type.equalsIgnoreCase("time")) { return new TimeLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("timestamp")) { return new TimestampLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("decimal")) { return new DecimalLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("char")) { return new CharLiteral(getLocation(context), value); } return new GenericLiteral(getLocation(context), type, value); }
@Override public Node visitGrant(SqlBaseParser.GrantContext context) { String grantee = context.grantee.getText(); Optional<List<String>> privileges; if (context.ALL() != null) { privileges = Optional.empty(); } else { privileges = Optional.of(context.privilege().stream() .map(SqlBaseParser.PrivilegeContext::getText) .collect(toList())); } return new Grant( getLocation(context), privileges, context.TABLE() != null, getQualifiedName(context.qualifiedName()), grantee, context.OPTION() != null); }
@Override public Node visitTypeConstructor(SqlBaseParser.TypeConstructorContext context) { String type = context.identifier().getText(); String value = unquote(context.STRING().getText()); if (type.equalsIgnoreCase("time")) { return new TimeLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("timestamp")) { return new TimestampLiteral(getLocation(context), value); } return new GenericLiteral(getLocation(context), type, value); }
@Override public Node visitNamedArgument(SqlBaseParser.NamedArgumentContext context) { return new CallArgument(getLocation(context), context.identifier().getText(), (Expression) visit(context.expression())); }
@Override public Node visitAliasedRelation(SqlBaseParser.AliasedRelationContext context) { Relation child = (Relation) visit(context.relationPrimary()); if (context.identifier() == null) { return child; } return new AliasedRelation(getLocation(context), child, context.identifier().getText(), getColumnAliases(context.columnAliases())); }
@Override public Node visitExtract(SqlBaseParser.ExtractContext context) { return new Extract(getLocation(context), (Expression) visit(context.valueExpression()), Extract.Field.valueOf(context.identifier().getText().toUpperCase())); }
@Override public Node visitTableElement(SqlBaseParser.TableElementContext context) { return new TableElement(getLocation(context), context.identifier().getText(), getType(context.type())); }
@Override public Node visitNamedArgument(SqlBaseParser.NamedArgumentContext context) { return new CallArgument(getLocation(context), context.identifier().getText(), (Expression) visit(context.expression())); }
@Override public Node visitDereference(SqlBaseParser.DereferenceContext context) { return new DereferenceExpression(getLocation(context), (Expression) visit(context.base), context.fieldName.getText(), caseSensitive); }
@Override public Node visitNamedQuery(SqlBaseParser.NamedQueryContext context) { return new WithQuery(getLocation(context), context.name.getText(), (Query) visit(context.query()), getColumnAliases(context.columnAliases())); }
@Override public Node visitUse(SqlBaseParser.UseContext context) { return new Use(getLocation(context), getTextIfPresent(context.catalog), context.schema.getText()); }
@Override public Node visitExtract(SqlBaseParser.ExtractContext context) { String fieldString = context.identifier().getText(); Extract.Field field; try { field = Extract.Field.valueOf(fieldString.toUpperCase()); } catch (IllegalArgumentException e) { throw parseError("Invalid EXTRACT field: " + fieldString, context); } return new Extract(getLocation(context), (Expression) visit(context.valueExpression()), field); }
@Override public Node visitNamedArgument(SqlBaseParser.NamedArgumentContext context) { return new CallArgument(getLocation(context), context.identifier().getText(), (Expression) visit(context.expression())); }