Java Code Examples for org.apache.calcite.rex.RexLiteral#stringValue()
The following examples show how to use
org.apache.calcite.rex.RexLiteral#stringValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlImplementor.java From Bats with Apache License 2.0 | 5 votes |
@Override public SqlNode toSql(RexProgram program, RexNode rex) { if (rex.getKind() == SqlKind.LITERAL) { final RexLiteral literal = (RexLiteral) rex; if (literal.getTypeName().getFamily() == SqlTypeFamily.CHARACTER) { return new SqlIdentifier(RexLiteral.stringValue(literal), POS); } } return super.toSql(program, rex); }
Example 2
Source File: SimpleRexRemap.java From Bats with Apache License 2.0 | 5 votes |
private static PathSegment convertLiteral(RexLiteral literal) { switch (literal.getType().getSqlTypeName()) { case CHAR: return new PathSegment.NameSegment(RexLiteral.stringValue(literal)); case INTEGER: return new PathSegment.ArraySegment(RexLiteral.intValue(literal)); default: return null; } }
Example 3
Source File: FieldsReWriterUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Checks if operator call is using item star field. * Will return field name if true. null otherwise. * * @param rexCall operator call * @param fieldNames list of field names * @return field name, null otherwise */ public static String getFieldNameFromItemStarField(RexCall rexCall, List<String> fieldNames) { if (!SqlStdOperatorTable.ITEM.equals(rexCall.getOperator())) { return null; } if (rexCall.getOperands().size() != 2) { return null; } if (!(rexCall.getOperands().get(0) instanceof RexInputRef && rexCall.getOperands().get(1) instanceof RexLiteral)) { return null; } // get parent field reference from the first operand (ITEM($0, 'col_name' -> $0) // and check if it corresponds to the dynamic star RexInputRef rexInputRef = (RexInputRef) rexCall.getOperands().get(0); String parentFieldName = fieldNames.get(rexInputRef.getIndex()); if (!SchemaPath.DYNAMIC_STAR.equals(parentFieldName)) { return null; } // get field name from the second operand (ITEM($0, 'col_name') -> col_name) RexLiteral rexLiteral = (RexLiteral) rexCall.getOperands().get(1); if (SqlTypeName.CHAR.equals(rexLiteral.getType().getSqlTypeName())) { return RexLiteral.stringValue(rexLiteral); } return null; }
Example 4
Source File: Utilities.java From Bats with Apache License 2.0 | 5 votes |
/** * Converts literal into path segment based on its type. * For unsupported types, returns null. * * @param literal literal * @return new path segment, null otherwise */ public static PathSegment convertLiteral(RexLiteral literal) { switch (literal.getType().getSqlTypeName()) { case CHAR: return new PathSegment.NameSegment(RexLiteral.stringValue(literal)); case INTEGER: return new PathSegment.ArraySegment(RexLiteral.intValue(literal)); default: return null; } }
Example 5
Source File: PrelUtil.java From dremio-oss with Apache License 2.0 | 5 votes |
private PathSegment convertLiteral(RexLiteral literal) { switch (literal.getType().getSqlTypeName().getFamily()) { case CHARACTER: return new NameSegment(RexLiteral.stringValue(literal)); case NUMERIC: return new ArraySegment(RexLiteral.intValue(literal)); default: return null; } }
Example 6
Source File: SqlImplementor.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public SqlNode toSql(RexProgram program, RexNode rex) { if (rex.getKind() == SqlKind.LITERAL) { final RexLiteral literal = (RexLiteral) rex; if (literal.getTypeName().getFamily() == SqlTypeFamily.CHARACTER) { return new SqlIdentifier(RexLiteral.stringValue(literal), POS); } } return super.toSql(program, rex); }
Example 7
Source File: DremioRelToSqlConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public SqlNode toSql(RexProgram program, RexNode rex) { if (rex.getKind() == SqlKind.LITERAL) { final RexLiteral literal = (RexLiteral) rex; if (literal.getTypeName().getFamily() == SqlTypeFamily.CHARACTER) { return new SqlIdentifier(RexLiteral.stringValue(literal), POS); } } return super.toSql(program, rex); }
Example 8
Source File: PredicateAnalyzer.java From dremio-oss with Apache License 2.0 | 5 votes |
Object value() { if (isIntegral()) { return longValue(); } else if (isFloatingPoint()) { return doubleValue(); } else if (isBoolean()) { return booleanValue(); } else if (isString()) { return RexLiteral.stringValue(literal); } else { return rawValue(); } }
Example 9
Source File: PredicateAnalyzer.java From calcite with Apache License 2.0 | 5 votes |
Object value() { if (isIntegral()) { return longValue(); } else if (isFloatingPoint()) { return doubleValue(); } else if (isBoolean()) { return booleanValue(); } else if (isString()) { return RexLiteral.stringValue(literal); } else { return rawValue(); } }
Example 10
Source File: SqlImplementor.java From calcite with Apache License 2.0 | 5 votes |
@Override public SqlNode toSql(RexProgram program, RexNode rex) { if (rex.getKind() == SqlKind.LITERAL) { final RexLiteral literal = (RexLiteral) rex; if (literal.getTypeName().getFamily() == SqlTypeFamily.CHARACTER) { return new SqlIdentifier(RexLiteral.stringValue(literal), POS); } } return super.toSql(program, rex); }
Example 11
Source File: PredicateAnalyzer.java From dremio-oss with Apache License 2.0 | 4 votes |
public String stringValue() { return RexLiteral.stringValue(literal); }
Example 12
Source File: PigFilter.java From calcite with Apache License 2.0 | 4 votes |
/** * TODO: do proper literal to string conversion + escaping */ private String getLiteralAsString(RexLiteral literal) { return '\'' + RexLiteral.stringValue(literal) + '\''; }
Example 13
Source File: PredicateAnalyzer.java From calcite with Apache License 2.0 | 4 votes |
private NamedFieldExpression(RexLiteral literal) { this.name = literal == null ? null : RexLiteral.stringValue(literal); }
Example 14
Source File: PredicateAnalyzer.java From calcite with Apache License 2.0 | 4 votes |
String stringValue() { return RexLiteral.stringValue(literal); }