Search in sources :

Example 26 with Symbol

use of io.crate.analyze.symbol.Symbol in project crate by crate.

the class SymbolToTrueVisitorTest method testNotPredicate.

@Test
public void testNotPredicate() throws Exception {
    Symbol symbol = convertFromSQL(("not (clustered_by = 'foo')"));
    assertThat(symbol, isLiteral(true));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 27 with Symbol

use of io.crate.analyze.symbol.Symbol in project crate by crate.

the class SymbolToTrueVisitorTest method testNot_FalseAndSubstr.

@Test
public void testNot_FalseAndSubstr() throws Exception {
    Symbol symbol = convertFromSQL("not (false and substr(table_name, 1, 1) = '1')");
    assertThat(symbol, isLiteral(true));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 28 with Symbol

use of io.crate.analyze.symbol.Symbol in project crate by crate.

the class InsertFromSubQueryAnalyzerTest method assertCompatibleColumns.

private void assertCompatibleColumns(InsertFromSubQueryAnalyzedStatement statement) {
    List<Symbol> outputSymbols = statement.subQueryRelation().querySpec().outputs();
    assertThat(statement.columns().size(), is(outputSymbols.size()));
    for (int i = 0; i < statement.columns().size(); i++) {
        Symbol subQueryColumn = outputSymbols.get(i);
        assertThat(subQueryColumn, instanceOf(Symbol.class));
        Reference insertColumn = statement.columns().get(i);
        assertThat(subQueryColumn.valueType().isConvertableTo(insertColumn.valueType()), is(true));
    }
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Reference(io.crate.metadata.Reference)

Example 29 with Symbol

use of io.crate.analyze.symbol.Symbol in project crate by crate.

the class InsertFromValuesAnalyzerTest method testInsertFromValuesWithOnDuplicateKey.

@Test
public void testInsertFromValuesWithOnDuplicateKey() throws Exception {
    InsertFromValuesAnalyzedStatement statement = e.analyze("insert into users (id, name, other_id) values (1, 'Arthur', 10) " + "on duplicate key update name = substr(values (name), 1, 2), " + "other_id = other_id + 100");
    assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
    Symbol[] assignments = statement.onDuplicateKeyAssignments().get(0);
    assertThat(assignments.length, is(2));
    assertThat(assignments[0], isLiteral("Ar"));
    assertThat(assignments[1], isFunction(AddFunction.NAME));
    Function function = (Function) assignments[1];
    assertThat(function.arguments().get(0), isReference("other_id"));
}
Also used : Function(io.crate.analyze.symbol.Function) AddFunction(io.crate.operation.scalar.arithmetic.AddFunction) Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 30 with Symbol

use of io.crate.analyze.symbol.Symbol in project crate by crate.

the class TopNProjectionTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ImmutableList<Symbol> outputs = ImmutableList.of(new Value(DataTypes.BOOLEAN), new Value(DataTypes.INTEGER));
    TopNProjection p = new TopNProjection(5, 10, outputs);
    BytesStreamOutput out = new BytesStreamOutput();
    Projection.toStream(p, out);
    StreamInput in = StreamInput.wrap(out.bytes());
    TopNProjection p2 = (TopNProjection) Projection.fromStream(in);
    assertEquals(p, p2);
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Value(io.crate.analyze.symbol.Value) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) 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