@Override protected Type visitTimestampLiteral(TimestampLiteral node, StackableAstVisitorContext<AnalysisContext> context) { try { parseTimestampLiteral(session.getTimeZoneKey(), node.getValue()); } catch (Exception e) { throw new SemanticException(INVALID_LITERAL, node, "'%s' is not a valid timestamp literal", node.getValue()); } Type type; if (timestampHasTimeZone(node.getValue())) { type = TIMESTAMP_WITH_TIME_ZONE; } else { type = TIMESTAMP; } expressionTypes.put(node, type); return type; }
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; }
@Override protected RowExpression visitTimestampLiteral(TimestampLiteral node, Void context) { long value; if (types.get(node).equals(TIMESTAMP_WITH_TIME_ZONE)) { value = parseTimestampWithTimeZone(timeZoneKey, node.getValue()); } else { // parse in time zone of client value = parseTimestampWithoutTimeZone(timeZoneKey, node.getValue()); } return constant(value, types.get(node)); }
@Override protected Long visitTimestampLiteral(TimestampLiteral node, ConnectorSession session) { try { return parseTimestampLiteral(session.getTimeZoneKey(), node.getValue()); } catch (Exception e) { throw new SemanticException(INVALID_LITERAL, node, "'%s' is not a valid timestamp literal", node.getValue()); } }
@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); }
@Test public void testLiterals() throws Exception { assertExpression("TIME" + " 'abc'", new TimeLiteral("abc")); assertExpression("TIMESTAMP" + " 'abc'", new TimestampLiteral("abc")); assertExpression("INTERVAL '33' day", new IntervalLiteral("33", Sign.POSITIVE, IntervalField.DAY, Optional.empty())); assertExpression("INTERVAL '33' day to second", new IntervalLiteral("33", Sign.POSITIVE, IntervalField.DAY, Optional.of(IntervalField.SECOND))); }
@Override protected String visitTimestampLiteral(TimestampLiteral node, Void context) { return "TIMESTAMP '" + node.getValue() + "'"; }
@Override protected String visitTimestampLiteral(TimestampLiteral node, StackableAstVisitorContext<Integer> indent) { return "TIMESTAMP '" + node.getValue() + "'"; }
@Override protected String visitTimestampLiteral(TimestampLiteral node, Boolean unmangleNames) { return "TIMESTAMP '" + node.getValue() + "'"; }