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 visitTimeLiteral(TimeLiteral node, Void context) { long value; if (types.get(node).equals(TIME_WITH_TIME_ZONE)) { value = parseTimeWithTimeZone(node.getValue()); } else { // parse in time zone of client value = parseTimeWithoutTimeZone(timeZoneKey, node.getValue()); } return constant(value, types.get(node)); }
@Override protected Type visitTimeLiteral(TimeLiteral node, StackableAstVisitorContext<AnalysisContext> context) { Type type; if (timeHasTimeZone(node.getValue())) { type = TIME_WITH_TIME_ZONE; } else { type = TIME; } expressionTypes.put(node, type); return type; }
@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 visitTimeLiteral(TimeLiteral node, Void context) { return "TIME '" + node.getValue() + "'"; }
@Override protected String visitTimeLiteral(TimeLiteral node, StackableAstVisitorContext<Integer> indent) { return "TIME '" + node.getValue() + "'"; }
@Override protected Long visitTimeLiteral(TimeLiteral node, ConnectorSession session) { return parseTime(session.getTimeZoneKey(), node.getValue()); }
@Override protected String visitTimeLiteral(TimeLiteral node, Boolean unmangleNames) { return "TIME '" + node.getValue() + "'"; }
@Test public void testTime() throws Exception { assertExpression("TIME '03:04:05'", new TimeLiteral("03:04:05")); }