use of io.crate.expression.symbol.Literal in project crate by crate.
the class SelectStatementAnalyzerTest method testRewriteCountNull.
@Test
public void testRewriteCountNull() {
var executor = SQLExecutor.builder(clusterService).build();
AnalyzedRelation relation = executor.analyze("select count(null) from sys.nodes");
List<Symbol> outputSymbols = relation.outputs();
assertThat(outputSymbols.size(), is(1));
assertThat(outputSymbols.get(0), instanceOf(Literal.class));
assertThat(((Literal) outputSymbols.get(0)).value(), is(0L));
}
use of io.crate.expression.symbol.Literal in project crate by crate.
the class CompoundLiteralTest method testObjectConstructionWithExpressionsAsValues.
@Test
public void testObjectConstructionWithExpressionsAsValues() throws Exception {
Literal objectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{name = 1 + 2}"));
assertThat(objectLiteral.symbolType(), is(SymbolType.LITERAL));
assertThat(objectLiteral.value(), is(Map.<String, Object>of("name", 3)));
Literal nestedObjectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{a = {name = concat('foo', 'bar')}}"));
@SuppressWarnings("unchecked") Map<String, Object> values = (Map<String, Object>) nestedObjectLiteral.value();
assertThat(values, is(Map.of("a", Map.of("name", "foobar"))));
}
use of io.crate.expression.symbol.Literal in project crate by crate.
the class CompoundLiteralTest method testObjectConstruction.
@Test
public void testObjectConstruction() throws Exception {
Symbol s = expressions.asSymbol("{}");
assertThat(s, instanceOf(Literal.class));
Literal l = (Literal) s;
assertThat(l.value(), is(new HashMap<String, Object>()));
Literal objectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{ident='value'}"));
assertThat(objectLiteral.symbolType(), is(SymbolType.LITERAL));
assertThat(objectLiteral.valueType().id(), is(ObjectType.ID));
assertThat(objectLiteral.value(), is(Map.of("ident", "value")));
Literal multipleObjectLiteral = (Literal) expressions.normalize(expressions.asSymbol("{\"Ident\"=123.4, a={}, ident='string'}"));
Map<String, Object> values = (Map<String, Object>) multipleObjectLiteral.value();
assertThat(values, is(MapBuilder.<String, Object>newMapBuilder().put("Ident", 123.4d).put("a", new HashMap<String, Object>()).put("ident", "string").map()));
}
use of io.crate.expression.symbol.Literal in project crate by crate.
the class ProjectionToProjectorVisitor method visitWriterProjection.
@Override
public Projector visitWriterProjection(WriterProjection projection, Context context) {
InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns(context.txnCtx);
List<Input<?>> inputs = null;
if (!projection.inputs().isEmpty()) {
ctx.add(projection.inputs());
inputs = ctx.topLevelInputs();
}
projection = projection.normalize(normalizer, context.txnCtx);
String uri = DataTypes.STRING.sanitizeValue(SymbolEvaluator.evaluate(context.txnCtx, nodeCtx, projection.uri(), Row.EMPTY, SubQueryResults.EMPTY));
assert uri != null : "URI must not be null";
StringBuilder sb = new StringBuilder(uri);
Symbol resolvedFileName = normalizer.normalize(WriterProjection.DIRECTORY_TO_FILENAME, context.txnCtx);
assert resolvedFileName instanceof Literal : "resolvedFileName must be a Literal, but is: " + resolvedFileName;
assert resolvedFileName.valueType().id() == StringType.ID : "resolvedFileName.valueType() must be " + StringType.INSTANCE;
String fileName = (String) ((Literal) resolvedFileName).value();
if (!uri.endsWith("/")) {
sb.append("/");
}
sb.append(fileName);
if (projection.compressionType() == WriterProjection.CompressionType.GZIP) {
sb.append(".gz");
}
uri = sb.toString();
Map<ColumnIdent, Object> overwrites = symbolMapToObject(projection.overwrites(), ctx, context.txnCtx);
return new FileWriterProjector(threadPool.generic(), uri, projection.compressionType(), inputs, ctx.expressions(), overwrites, projection.outputNames(), projection.outputFormat(), fileOutputFactoryMap, projection.withClauseOptions());
}
use of io.crate.expression.symbol.Literal in project crate by crate.
the class RefAndLiteral method of.
@Nullable
public static RefAndLiteral of(Function function) {
List<Symbol> args = function.arguments();
assert args.size() == 2 : "Function must have 2 arguments";
Symbol fst = args.get(0);
Symbol snd = args.get(1);
if (fst instanceof Reference && snd instanceof Literal) {
return new RefAndLiteral((Reference) fst, (Literal) snd);
} else {
return null;
}
}
Aggregations