use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class ReferenceToLiteralConverterTest method testReplaceSimpleReference.
@Test
public void testReplaceSimpleReference() throws Exception {
Object[] inputValues = new Object[] { 1 };
Reference idRef = new Reference(new ReferenceIdent(TABLE_IDENT, new ColumnIdent("id")), RowGranularity.DOC, DataTypes.INTEGER);
ReferenceToLiteralConverter.Context context = new ReferenceToLiteralConverter.Context(ImmutableList.of(idRef), ImmutableList.of(idRef));
context.values(inputValues);
Symbol replacedSymbol = REFERENCE_TO_LITERAL_CONVERTER.process(idRef, context);
assertThat(replacedSymbol, isLiteral(1, DataTypes.INTEGER));
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class InsertFromSubQueryAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.
@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
InsertFromSubQueryAnalyzedStatement statement = e.analyze("insert into users (id, name) (select id, name from users) " + "on duplicate key update name = substr(values (name), 1, 1)");
Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
assertThat(entry.getKey(), isReference("name"));
assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
Function function = (Function) entry.getValue();
assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
InputColumn inputColumn = (InputColumn) function.arguments().get(0);
assertThat(inputColumn.index(), is(1));
assertThat(inputColumn.valueType(), instanceOf(StringType.class));
}
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class SymbolToTrueVisitorTest method testComplexNestedDifferentMethodsEvaluatesToFalse.
@Test
public void testComplexNestedDifferentMethodsEvaluatesToFalse() throws Exception {
Symbol symbol = convertFromSQL("(number_of_shards = 1 or number_of_replicas = 3 and schema_name = 'sys' " + "or not (number_of_shards = 2)) and substr(table_name, 1, 1) = '1' and false");
assertThat(symbol, isLiteral(false));
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class SymbolToTrueVisitorTest method testIsNull.
@Test
public void testIsNull() throws Exception {
Symbol symbol = convertFromSQL("clustered_by is null");
assertThat(symbol, isLiteral(true));
}
use of io.crate.analyze.symbol.Symbol in project crate by crate.
the class SymbolToTrueVisitorTest method testNot_NullAndSubstr.
@Test
public void testNot_NullAndSubstr() throws Exception {
Symbol symbol = convertFromSQL("not (null and substr(table_name, 1, 1) = '1')");
assertThat(symbol, isLiteral(null));
}
Aggregations