@Override public Node visitBooleanValue(SqlBaseParser.BooleanValueContext context) { return new BooleanLiteral(getLocation(context), context.getText()); }
private static Expression booleanConstant(@Nullable Boolean value) { if (value == null) { return new Cast(new NullLiteral(), BOOLEAN.toString()); } return new BooleanLiteral(value.toString()); }
private static Expression toExpression(Object value) throws PrestoException { if (value instanceof String) { return new StringLiteral(value.toString()); } if (value instanceof Boolean) { return new BooleanLiteral(value.toString()); } if (value instanceof Long || value instanceof Integer) { return new LongLiteral(value.toString()); } if (value instanceof Double) { return new DoubleLiteral(value.toString()); } if (value instanceof List) { List<?> list = (List<?>) value; return new ArrayConstructor(list.stream() .map(Visitor::toExpression) .collect(toList())); } throw new PrestoException(INVALID_TABLE_PROPERTY, format("Failed to convert object of type %s to expression: %s", value.getClass().getName(), value)); }
private static Row createDescribeOutputRow(Field field, Analysis analysis) { LongLiteral typeSize = new LongLiteral("0"); if (field.getType() instanceof FixedWidthType) { typeSize = new LongLiteral(String.valueOf(((FixedWidthType) field.getType()).getFixedSize())); } String columnName; if (field.getName().isPresent()) { columnName = field.getName().get(); } else { int columnIndex = ImmutableList.copyOf(analysis.getOutputDescriptor().getVisibleFields()).indexOf(field); columnName = "_col" + columnIndex; } Optional<QualifiedObjectName> originTable = field.getOriginTable(); return row( new StringLiteral(columnName), new StringLiteral(originTable.map(QualifiedObjectName::getCatalogName).orElse("")), new StringLiteral(originTable.map(QualifiedObjectName::getSchemaName).orElse("")), new StringLiteral(originTable.map(QualifiedObjectName::getObjectName).orElse("")), new StringLiteral(field.getType().getDisplayName()), typeSize, new BooleanLiteral(String.valueOf(field.isAliased()))); }
@Test public void testIf() { assertExpression("if(true, 1, 0)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("1"), new LongLiteral("0"))); assertExpression("if(true, 3, null)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), new NullLiteral())); assertExpression("if(false, null, 4)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new LongLiteral("4"))); assertExpression("if(false, null, null)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new NullLiteral())); assertExpression("if(true, 3)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), null)); assertInvalidExpression("IF(true)", "Invalid number of arguments for 'if' function"); assertInvalidExpression("IF(true, 1, 0) FILTER (WHERE true)", "FILTER not valid for 'if' function"); assertInvalidExpression("IF(true, 1, 0) OVER()", "OVER clause not valid for 'if' function"); }
return new BooleanLiteral(object.toString());
@Override public Node visitBooleanValue(SqlBaseParser.BooleanValueContext context) { return new BooleanLiteral(getLocation(context), context.getText()); }
@Override public Node visitBooleanValue(SqlBaseParser.BooleanValueContext context) { return new BooleanLiteral(getLocation(context), context.getText()); }
@Test public void testIf() { assertExpression("if(true, 1, 0)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("1"), new LongLiteral("0"))); assertExpression("if(true, 3, null)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), new NullLiteral())); assertExpression("if(false, null, 4)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new LongLiteral("4"))); assertExpression("if(false, null, null)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new NullLiteral())); assertExpression("if(true, 3)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), null)); assertInvalidExpression("IF(true)", "Invalid number of arguments for 'if' function"); assertInvalidExpression("IF(true, 1, 0) FILTER (WHERE true)", "FILTER not valid for 'if' function"); assertInvalidExpression("IF(true, 1, 0) OVER()", "OVER clause not valid for 'if' function"); }
return new BooleanLiteral(object.toString());
postInnerJoinCriteria = new BooleanLiteral("TRUE");