@Override protected Void visitStringLiteral(StringLiteral node, Integer indentLevel) { print(indentLevel, "String[" + node.getValue() + "]"); return null; }
@Override protected String visitStringLiteral(StringLiteral node, Void context) { return formatStringLiteral(node.getValue()); }
@Override public Node visitInterval(SqlBaseParser.IntervalContext context) { return new IntervalLiteral( getLocation(context), ((StringLiteral) visit(context.string())).getValue(), Optional.ofNullable(context.sign) .map(AstBuilder::getIntervalSign) .orElse(IntervalLiteral.Sign.POSITIVE), getIntervalFieldType((Token) context.from.getChild(0).getPayload()), Optional.ofNullable(context.to) .map((x) -> x.getChild(0).getPayload()) .map(Token.class::cast) .map(AstBuilder::getIntervalFieldType)); }
@Override public Node visitColumnDefinition(SqlBaseParser.ColumnDefinitionContext context) { Optional<String> comment = Optional.empty(); if (context.COMMENT() != null) { comment = Optional.of(((StringLiteral) visit(context.string())).getValue()); } List<Property> properties = ImmutableList.of(); if (context.properties() != null) { properties = visit(context.properties().property(), Property.class); } return new ColumnDefinition( getLocation(context), (Identifier) visit(context.identifier()), getType(context.type()), properties, comment); }
@Override public Node visitCreateTable(SqlBaseParser.CreateTableContext context) { Optional<String> comment = Optional.empty(); if (context.COMMENT() != null) { comment = Optional.of(((StringLiteral) visit(context.string())).getValue()); } List<Property> properties = ImmutableList.of(); if (context.properties() != null) { properties = visit(context.properties().property(), Property.class); } return new CreateTable( getLocation(context), getQualifiedName(context.qualifiedName()), visit(context.tableElement(), TableElement.class), context.EXISTS() != null, properties, comment); }
@Override public Node visitCreateTableAsSelect(SqlBaseParser.CreateTableAsSelectContext context) { Optional<String> comment = Optional.empty(); if (context.COMMENT() != null) { comment = Optional.of(((StringLiteral) visit(context.string())).getValue()); } Optional<List<Identifier>> columnAliases = Optional.empty(); if (context.columnAliases() != null) { columnAliases = Optional.of(visit(context.columnAliases().identifier(), Identifier.class)); } List<Property> properties = ImmutableList.of(); if (context.properties() != null) { properties = visit(context.properties().property(), Property.class); } return new CreateTableAsSelect( getLocation(context), getQualifiedName(context.qualifiedName()), (Query) visit(context.query()), context.EXISTS() != null, properties, context.NO() == null, columnAliases, comment); }
@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 protected String visitStringLiteral(StringLiteral node, Boolean negate) { return "'" + node.getValue().replace("'", "''") + "'"; }
@Override protected String visitStringLiteral(StringLiteral node, Boolean unmangleNames) { String variableName = ":" + variable[1]++; valueBuilder.put(variableName, new AttributeValue(node.getValue())); return variableName; }
@Override protected String visitStringLiteral(StringLiteral node, Void context) { return formatStringLiteral(node.getValue()); }
String value = ((StringLiteral) node.getPattern()).getValue();
String pattern = ((StringLiteral) node.getPattern()).getValue(); if (pattern.endsWith("%") && pattern.startsWith("%")) { template = "contains(%s, %s)";
@Override protected Void visitStringLiteral(StringLiteral node, Integer indentLevel) { print(indentLevel, "String[" + node.getValue() + "]"); return null; }
@Override protected Void visitStringLiteral(StringLiteral node, Integer indentLevel) { print(indentLevel, "String[" + node.getValue() + "]"); return null; }
/** * Visited for every string literal. */ @Override public Void visitStringLiteral(StringLiteral node, Boolean capture) { translation.append(node.getValue()); return null; }
@Override protected String visitStringLiteral(StringLiteral node, Void context) { return formatStringLiteral(node.getValue()); }
@Override protected String visitStringLiteral(StringLiteral node, Boolean unmangleNames) { return formatStringLiteral(node.getValue()); }
private Object getLiteralValue(Expression expression) throws SQLException{ if(expression instanceof LongLiteral) return ((LongLiteral)expression).getValue(); else if(expression instanceof BooleanLiteral) return ((BooleanLiteral)expression).getValue(); else if(expression instanceof DoubleLiteral) return ((DoubleLiteral)expression).getValue(); else if(expression instanceof StringLiteral) return ((StringLiteral)expression).getValue(); throw new SQLException("Unsupported literal type: "+expression); }
private Object getObject(Literal literal){ Object value = null; if(literal instanceof LongLiteral) value = ((LongLiteral)literal).getValue(); else if(literal instanceof BooleanLiteral) value = ((BooleanLiteral)literal).getValue(); else if(literal instanceof DoubleLiteral) value = ((DoubleLiteral)literal).getValue(); else if(literal instanceof StringLiteral) value = ((StringLiteral)literal).getValue(); else if(literal instanceof TimeLiteral) value = ((TimeLiteral)literal).getValue(); else if(literal instanceof TimestampLiteral) value = ((TimestampLiteral)literal).getValue(); return value; }