@Test public void testAtTimeZone() { assertStatement("SELECT timestamp '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles'", new Query( Optional.empty(), new QuerySpecification( selectList( new AtTimeZone(new TimestampLiteral("2012-10-31 01:00 UTC"), new StringLiteral("America/Los_Angeles"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty())); }
@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); }
@Test public void testLiterals() { 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))); assertExpression("CHAR 'abc'", new CharLiteral("abc")); }
@Test public void testAtTimeZone() { assertStatement("SELECT timestamp '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles'", new Query( Optional.empty(), new QuerySpecification( selectList( new AtTimeZone(new TimestampLiteral("2012-10-31 01:00 UTC"), new StringLiteral("America/Los_Angeles")) ), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty()), ImmutableList.<SortItem>of(), Optional.empty(), Optional.empty())); }
@Test public void testAtTimeZone() { assertStatement("SELECT timestamp '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles'", new Query( Optional.empty(), new QuerySpecification( selectList( new AtTimeZone(new TimestampLiteral("2012-10-31 01:00 UTC"), new StringLiteral("America/Los_Angeles"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty())); }
@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 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); }
@Test public void testLiterals() { 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))); assertExpression("CHAR 'abc'", new CharLiteral("abc")); }