Search in sources :

Example 6 with DataType

use of io.crate.types.DataType in project crate by crate.

the class DocIndexMetaDataTest method testStringArrayWithFulltextIndex.

@Test
public void testStringArrayWithFulltextIndex() throws Exception {
    DocIndexMetaData metaData = getDocIndexMetaDataFromStatement("create table t (tags array(string) index using fulltext)");
    Reference reference = metaData.columns().get(0);
    assertThat(reference.valueType(), equalTo((DataType) new ArrayType(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with DataType

use of io.crate.types.DataType in project crate by crate.

the class SelectStatementAnalyzerTest method testCastExpression.

@Test
public void testCastExpression() throws Exception {
    SelectAnalyzedStatement analysis = analyze("select cast(other_id as string) from users");
    assertThat(analysis.relation().querySpec().outputs().get(0), isFunction(CastFunctionResolver.FunctionNames.TO_STRING, Arrays.<DataType>asList(DataTypes.LONG)));
    analysis = analyze("select cast(1+1 as string) from users");
    assertThat(analysis.relation().querySpec().outputs().get(0), isLiteral("2", DataTypes.STRING));
    analysis = analyze("select cast(friends['id'] as array(string)) from users");
    assertThat(analysis.relation().querySpec().outputs().get(0), isFunction(CastFunctionResolver.FunctionNames.TO_STRING_ARRAY, Arrays.<DataType>asList(new ArrayType(DataTypes.LONG))));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with DataType

use of io.crate.types.DataType in project crate by crate.

the class SelectStatementAnalyzerTest method testAnyRightLiteral.

@Test
public void testAnyRightLiteral() throws Exception {
    SelectAnalyzedStatement stmt = analyze("select id from sys.shards where id = any ([1,2])");
    WhereClause whereClause = stmt.relation().querySpec().where();
    assertThat(whereClause.hasQuery(), is(true));
    assertThat(whereClause.query(), isFunction("any_=", ImmutableList.<DataType>of(DataTypes.INTEGER, new ArrayType(DataTypes.INTEGER))));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with DataType

use of io.crate.types.DataType in project crate by crate.

the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParam.

@Test
public void testUpdateDynamicNestedArrayParam() throws Exception {
    UpdateAnalyzedStatement statement = analyze("update users set new=? where id=1", new Object[] { new Object[] { new Object[] { 1.9, 4.8 }, new Object[] { 9.7, 12.7 } } });
    DataType dataType = statement.nestedStatements().get(0).assignments().values().iterator().next().valueType();
    assertThat(dataType, is((DataType) new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with DataType

use of io.crate.types.DataType in project crate by crate.

the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParamLiteral.

@Test
public void testUpdateDynamicNestedArrayParamLiteral() throws Exception {
    UpdateAnalyzedStatement statement = analyze("update users set new=[[1.9, 4.8], [9.7, 12.7]]");
    DataType dataType = statement.nestedStatements().get(0).assignments().values().iterator().next().valueType();
    assertThat(dataType, is((DataType) new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

DataType (io.crate.types.DataType)64 ArrayType (io.crate.types.ArrayType)30 Test (org.junit.Test)30 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28 FunctionIdent (io.crate.metadata.FunctionIdent)8 FunctionInfo (io.crate.metadata.FunctionInfo)7 WhereClause (io.crate.analyze.WhereClause)6 Symbol (io.crate.analyze.symbol.Symbol)4 Function (io.crate.analyze.symbol.Function)3 Input (io.crate.data.Input)3 Map (java.util.Map)3 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 Reference (io.crate.metadata.Reference)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 TableInfo (io.crate.metadata.table.TableInfo)2 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)2 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)2 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)2 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)2