@Override protected Void visitBooleanLiteral(BooleanLiteral node, Integer indentLevel) { print(indentLevel, "Boolean[" + node.getValue() + "]"); return null; }
@Override public Node visitBooleanValue(SqlBaseParser.BooleanValueContext context) { return new BooleanLiteral(getLocation(context), context.getText()); }
@Override protected Object visitBooleanLiteral(BooleanLiteral node, Object context) { return node.equals(BooleanLiteral.TRUE_LITERAL); }
@Override protected Object visitBooleanLiteral(BooleanLiteral node, ConnectorSession session) { return node.getValue(); }
private static Expression booleanConstant(@Nullable Boolean value) { if (value == null) { return new Cast(new NullLiteral(), BOOLEAN.toString()); } return new BooleanLiteral(value.toString()); }
private JoinEnumerationResult getJoinSource(LinkedHashSet<PlanNode> nodes, List<Symbol> outputSymbols) { if (nodes.size() == 1) { PlanNode planNode = getOnlyElement(nodes); ImmutableList.Builder<Expression> predicates = ImmutableList.builder(); predicates.addAll(allFilterInference.generateEqualitiesPartitionedBy(outputSymbols::contains).getScopeEqualities()); stream(nonInferrableConjuncts(allFilter)) .map(conjunct -> allFilterInference.rewriteExpression(conjunct, outputSymbols::contains)) .filter(Objects::nonNull) .forEach(predicates::add); Expression filter = combineConjuncts(predicates.build()); if (!TRUE_LITERAL.equals(filter)) { planNode = new FilterNode(idAllocator.getNextId(), planNode, filter); } return createJoinEnumerationResult(planNode); } return chooseJoinOrder(nodes, outputSymbols); }
@Override protected String visitBooleanLiteral(BooleanLiteral node, Void context) { return String.valueOf(node.getValue()); }
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)); }
@Override public PlanNode visitTableScan(TableScanNode node, RewriteContext<Expression> context) { Expression predicate = simplifyExpression(context.get()); if (!TRUE_LITERAL.equals(predicate)) { return new FilterNode(idAllocator.getNextId(), node, predicate); } return node; }
@Override protected RowExpression visitBooleanLiteral(BooleanLiteral node, Void context) { return constant(node.getValue(), BOOLEAN); }
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()))); }
decomposedPredicate.getRemainingExpression()); if (!TRUE_LITERAL.equals(resultingPredicate)) { return new FilterNode(idAllocator.getNextId(), tableScan, resultingPredicate);
@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"); }
@Override protected Object visitBooleanLiteral(BooleanLiteral node, Object context) { return node.equals(BooleanLiteral.TRUE_LITERAL); }
@Override protected PlanNodeStatsEstimate visitBooleanLiteral(BooleanLiteral node, Void context) { if (node.getValue()) { return input; } PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.builder(); result.setOutputRowCount(0.0); input.getSymbolsWithKnownStatistics().forEach(symbol -> result.addSymbolStatistics(symbol, SymbolStatsEstimate.zero())); return result.build(); }
return new BooleanLiteral(object.toString());
@Override public PlanNode visitTableScan(TableScanNode node, RewriteContext<Expression> context) { Expression predicate = simplifyExpression(context.get()); if (!BooleanLiteral.TRUE_LITERAL.equals(predicate)) { return new FilterNode(idAllocator.getNextId(), node, predicate); } return node; } }
private static String getValueFromLiteral(Node expression) { if (expression instanceof LongLiteral) { return String.valueOf(((LongLiteral) expression).getValue()); } else if (expression instanceof BooleanLiteral) { return String.valueOf(((BooleanLiteral) expression).getValue()); } else if (expression instanceof DoubleLiteral) { return String.valueOf(((DoubleLiteral) expression).getValue()); } else if (expression instanceof DecimalLiteral) { return String.valueOf(((DecimalLiteral) expression).getValue()); } else if (expression instanceof GenericLiteral) { return ((GenericLiteral) expression).getValue(); } else { throw new IllegalArgumentException("Unsupported literal expression type: " + expression.getClass().getName()); } }
@Override public Node visitBooleanValue(SqlBaseParser.BooleanValueContext context) { return new BooleanLiteral(getLocation(context), context.getText()); }