Search in sources :

Example 21 with Symbol

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));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with Symbol

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));
    }
}
Also used : Function(io.crate.analyze.symbol.Function) SubstrFunction(io.crate.operation.scalar.SubstrFunction) StringType(io.crate.types.StringType) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) Map(java.util.Map) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 23 with Symbol

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));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 24 with Symbol

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));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 25 with Symbol

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));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Symbol (io.crate.analyze.symbol.Symbol)109 Test (org.junit.Test)51 CrateUnitTest (io.crate.test.integration.CrateUnitTest)40 Function (io.crate.analyze.symbol.Function)14 Input (io.crate.data.Input)14 Reference (io.crate.metadata.Reference)11 WhereClause (io.crate.analyze.WhereClause)10 InputColumn (io.crate.analyze.symbol.InputColumn)8 InputFactory (io.crate.operation.InputFactory)8 OrderBy (io.crate.analyze.OrderBy)7 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)6 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)6 AbstractScalarFunctionsTest (io.crate.operation.scalar.AbstractScalarFunctionsTest)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6 ImmutableList (com.google.common.collect.ImmutableList)5 DocTableInfo (io.crate.metadata.doc.DocTableInfo)5 TableInfo (io.crate.metadata.table.TableInfo)5 QuerySpec (io.crate.analyze.QuerySpec)4 Literal (io.crate.analyze.symbol.Literal)4