Search in sources :

Example 6 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class RestActionReceiversTest method testRestResultSetReceiver.

@Test
public void testRestResultSetReceiver() throws Exception {
    RestResultSetReceiver receiver = new RestResultSetReceiver(newChannel(), fields, 0L, true);
    for (Row row : rows) {
        receiver.setNextRow(row);
    }
    XContentBuilder actualBuilder = receiver.finishBuilder();
    ResultToXContentBuilder builder = ResultToXContentBuilder.builder(newChannel());
    builder.cols(fields);
    builder.colTypes(fields);
    builder.startRows();
    for (Row row : rows) {
        builder.addRow(row, 3);
    }
    builder.finishRows();
    builder.rowCount(rows.size());
    assertXContentBuilder(actualBuilder, builder.build());
}
Also used : Row(io.crate.data.Row) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder 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 8 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testExtractColumnDefinitionsFromEmptyIndex.

@Test
public void testExtractColumnDefinitionsFromEmptyIndex() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).endObject().endObject();
    IndexMetaData metaData = getIndexMetaData("test2", builder);
    DocIndexMetaData md = newMeta(metaData, "test2");
    assertThat(md.columns(), hasSize(0));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testNestedColumnIdent.

@Test
public void testNestedColumnIdent() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("person").startObject("properties").startObject("addresses").startObject("properties").startObject("city").field("type", "string").field("index", "not_analyzed").endObject().startObject("country").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().endObject().endObject();
    IndexMetaData metaData = getIndexMetaData("test1", builder);
    DocIndexMetaData md = newMeta(metaData, "test1");
    Reference reference = md.references().get(new ColumnIdent("person", Arrays.asList("addresses", "city")));
    assertNotNull(reference);
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.

the class DocIndexMetaDataTest method testVersionsRead.

@Test
public void testVersionsRead() throws Exception {
    // @formatter:off
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").startObject("version").startObject(Version.Property.CREATED.toString()).field(Version.CRATEDB_VERSION_KEY, 560499).field(Version.ES_VERSION_KEY, 2040299).endObject().startObject(Version.Property.UPGRADED.toString()).field(Version.CRATEDB_VERSION_KEY, Version.CURRENT.id).field(Version.ES_VERSION_KEY, Version.CURRENT.esVersion.id).endObject().endObject().endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().endObject();
    // @formatter: on
    IndexMetaData metaData = getIndexMetaData("test1", builder, Settings.EMPTY, null);
    DocIndexMetaData md = newMeta(metaData, "test1");
    assertThat(md.versionCreated().id, is(560499));
    assertThat(md.versionCreated().esVersion.id, is(2040299));
    assertThat(md.versionUpgraded(), is(Version.CURRENT));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)618 IOException (java.io.IOException)126 XContentParser (org.elasticsearch.common.xcontent.XContentParser)122 Settings (org.elasticsearch.common.settings.Settings)60 ArrayList (java.util.ArrayList)59 SearchResponse (org.elasticsearch.action.search.SearchResponse)56 Matchers.containsString (org.hamcrest.Matchers.containsString)53 HashMap (java.util.HashMap)47 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)43 Map (java.util.Map)41 RestRequest (org.elasticsearch.rest.RestRequest)37 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)36 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)35 Test (org.junit.Test)34 RestController (org.elasticsearch.rest.RestController)33 NodeClient (org.elasticsearch.client.node.NodeClient)32 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)32 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)32 GeoPoint (org.elasticsearch.common.geo.GeoPoint)31 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28