Search in sources :

Example 1 with ArrayType

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

the class LuceneQueryBuilderTest method prepare.

@Before
public void prepare() throws Exception {
    DocTableInfo users = TestingTableInfo.builder(new TableIdent(null, "users"), null).add("name", DataTypes.STRING).add("x", DataTypes.INTEGER).add("d", DataTypes.DOUBLE).add("d_array", new ArrayType(DataTypes.DOUBLE)).add("y_array", new ArrayType(DataTypes.LONG)).add("shape", DataTypes.GEO_SHAPE).add("point", DataTypes.GEO_POINT).build();
    TableRelation usersTr = new TableRelation(users);
    sources = ImmutableMap.of(new QualifiedName("users"), usersTr);
    expressions = new SqlExpressions(sources, usersTr);
    builder = new LuceneQueryBuilder(expressions.getInstance(Functions.class));
    indexCache = mock(IndexCache.class, Answers.RETURNS_MOCKS.get());
    Path tempDir = createTempDir();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("path.home", tempDir).build();
    Index index = new Index(users.ident().indexName());
    when(indexCache.indexSettings()).thenReturn(indexSettings);
    AnalysisService analysisService = createAnalysisService(indexSettings, index);
    mapperService = createMapperService(index, indexSettings, analysisService);
    // @formatter:off
    XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("default").startObject("properties").startObject("name").field("type", "string").endObject().startObject("x").field("type", "integer").endObject().startObject("d").field("type", "double").endObject().startObject("point").field("type", "geo_point").endObject().startObject("shape").field("type", "geo_shape").endObject().startObject("d_array").field("type", "array").startObject("inner").field("type", "double").endObject().endObject().startObject("y_array").field("type", "array").startObject("inner").field("type", "integer").endObject().endObject().endObject().endObject().endObject();
    // @formatter:on
    mapperService.merge("default", new CompressedXContent(xContentBuilder.bytes()), MapperService.MergeReason.MAPPING_UPDATE, true);
    indexFieldDataService = mock(IndexFieldDataService.class);
    IndexFieldData geoFieldData = mock(IndexGeoPointFieldData.class);
    when(geoFieldData.getFieldNames()).thenReturn(new MappedFieldType.Names("point"));
    when(indexFieldDataService.getForField(mapperService.smartNameFieldType("point"))).thenReturn(geoFieldData);
}
Also used : Path(java.nio.file.Path) DocTableInfo(io.crate.metadata.doc.DocTableInfo) QualifiedName(io.crate.sql.tree.QualifiedName) TableIdent(io.crate.metadata.TableIdent) Index(org.elasticsearch.index.Index) TableRelation(io.crate.analyze.relations.TableRelation) ArrayType(io.crate.types.ArrayType) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) IndexCache(org.elasticsearch.index.cache.IndexCache) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) AnalysisService(org.elasticsearch.index.analysis.AnalysisService) SqlExpressions(io.crate.testing.SqlExpressions) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Before(org.junit.Before)

Example 2 with ArrayType

use of io.crate.types.ArrayType 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 3 with ArrayType

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

the class ParameterContextTest method testBulkNestedNestedEmpty.

@Test
public void testBulkNestedNestedEmpty() throws Exception {
    Object[][] bulkArgs = new Object[][] { new Object[] { new String[][] { new String[0] } }, new Object[] { new String[][] { new String[0] } } };
    ParameterContext ctx = new ParameterContext(Row.EMPTY, Rows.of(bulkArgs));
    assertThat(ctx.getAsSymbol(0), isLiteral(bulkArgs[0][0], new ArrayType(new ArrayType(DataTypes.UNDEFINED))));
}
Also used : ArrayType(io.crate.types.ArrayType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with ArrayType

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

the class CopyAnalyzerTest method testCopyFromFileUriArray.

@Test
public void testCopyFromFileUriArray() throws Exception {
    Object[] files = $("/f1.json", "/f2.json");
    CopyFromAnalyzedStatement copyFrom = e.analyze("copy users from ?", new Object[] { files });
    assertThat(copyFrom.uri(), isLiteral($(new BytesRef("/f1.json"), new BytesRef("/f2.json")), new ArrayType(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with ArrayType

use of io.crate.types.ArrayType 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)

Aggregations

ArrayType (io.crate.types.ArrayType)76 Test (org.junit.Test)53 DataType (io.crate.types.DataType)35 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 Symbol (io.crate.expression.symbol.Symbol)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 BytesRef (org.apache.lucene.util.BytesRef)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)7 Literal (io.crate.analyze.symbol.Literal)6 Literal (io.crate.expression.symbol.Literal)6 ColumnIdent (io.crate.metadata.ColumnIdent)6 Input (io.crate.data.Input)5 HashMap (java.util.HashMap)5 Function (io.crate.analyze.symbol.Function)4 Reference (io.crate.metadata.Reference)4 DataTypes (io.crate.types.DataTypes)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 TransactionContext (io.crate.metadata.TransactionContext)3