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());
}
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);
}
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));
}
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);
}
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));
}
Aggregations