use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.
the class DocIndexMetaDataTest method testNewArrayMapping.
@Test
public void testNewArrayMapping() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "string").field("index", "no").endObject().startObject("array_col").field("type", "array").startObject("inner").field("type", "ip").field("index", "not_analyzed").endObject().endObject().startObject("nested").field("type", "object").startObject("properties").startObject("inner_nested").field("type", "array").startObject("inner").field("type", "date").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().endObject();
IndexMetaData indexMetaData = getIndexMetaData("test1", builder);
DocIndexMetaData docIndexMetaData = newMeta(indexMetaData, "test1");
assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("array_col")).valueType(), is((DataType) new ArrayType(DataTypes.IP)));
assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("nested.inner_nested")).valueType(), is((DataType) new ArrayType(DataTypes.TIMESTAMP)));
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.
the class DocIndexMetaDataTest method testExtractPrimaryKey.
@Test
public void testExtractPrimaryKey() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "string").field("index", "no").endObject().startObject("datum").field("type", "date").endObject().startObject("content").field("type", "string").field("index", "analyzed").field("analyzer", "standard").endObject().endObject().endObject().endObject();
IndexMetaData metaData = getIndexMetaData("test3", builder);
DocIndexMetaData md = newMeta(metaData, "test3");
assertThat(md.primaryKey().size(), is(1));
assertThat(md.primaryKey(), contains(new ColumnIdent("id")));
builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject();
md = newMeta(getIndexMetaData("test4", builder), "test4");
// _id is always the fallback primary key
assertThat(md.primaryKey().size(), is(1));
builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).endObject().endObject();
md = newMeta(getIndexMetaData("test5", builder), "test5");
assertThat(md.primaryKey().size(), is(1));
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.
the class DocIndexMetaDataTest method extractRoutingColumn.
@Test
public void extractRoutingColumn() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "multi_field").field("path", "just_name").startObject("fields").startObject("title").field("type", "string").field("index", "not_analyzed").endObject().startObject("ft").field("type", "string").field("index", "analyzed").field("analyzer", "english").endObject().endObject().endObject().startObject("datum").field("type", "date").endObject().startObject("content").field("type", "multi_field").field("path", "just_name").startObject("fields").startObject("content").field("type", "string").field("index", "no").endObject().startObject("ft").field("type", "string").field("index", "analyzed").field("analyzer", "english").endObject().endObject().endObject().endObject().endObject().endObject();
DocIndexMetaData md = newMeta(getIndexMetaData("test8", builder), "test8");
assertThat(md.routingCol(), is(new ColumnIdent("id")));
builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject();
md = newMeta(getIndexMetaData("test9", builder), "test8");
assertThat(md.routingCol(), is(new ColumnIdent("_id")));
builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("_meta").array("primary_keys", "id", "num").field("routing", "num").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("num").field("type", "long").field("index", "not_analyzed").endObject().startObject("content").field("type", "string").field("index", "no").endObject().endObject().endObject().endObject();
md = newMeta(getIndexMetaData("test10", builder), "test10");
assertThat(md.routingCol(), is(new ColumnIdent("num")));
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.
the class DocIndexMetaDataTest method testDocSysColumnReferences.
@Test
public void testDocSysColumnReferences() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(Constants.DEFAULT_MAPPING_TYPE).startObject("properties").startObject("content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject();
DocIndexMetaData metaData = newMeta(getIndexMetaData("test", builder), "test");
Reference id = metaData.references().get(new ColumnIdent("_id"));
assertNotNull(id);
Reference version = metaData.references().get(new ColumnIdent("_version"));
assertNotNull(version);
Reference score = metaData.references().get(new ColumnIdent("_score"));
assertNotNull(score);
}
use of org.elasticsearch.common.xcontent.XContentBuilder in project crate by crate.
the class DocIndexMetaDataTest method testSchemaWithGeneratedColumn.
@Test
public void testSchemaWithGeneratedColumn() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").startObject("generated_columns").field("week", "date_trunc('week', ts)").endObject().endObject().startObject("properties").startObject("ts").field("type", "date").endObject().startObject("week").field("type", "long").endObject().endObject();
IndexMetaData metaData = getIndexMetaData("test1", builder, Settings.EMPTY, null);
DocIndexMetaData md = newMeta(metaData, "test1");
assertThat(md.columns().size(), is(2));
Reference week = md.references().get(new ColumnIdent("week"));
assertThat(week, Matchers.notNullValue());
assertThat(week, instanceOf(GeneratedReference.class));
assertThat(((GeneratedReference) week).formattedGeneratedExpression(), is("date_trunc('week', ts)"));
assertThat(((GeneratedReference) week).generatedExpression(), isFunction("date_trunc", isLiteral("week"), isReference("ts")));
assertThat(((GeneratedReference) week).referencedReferences(), contains(isReference("ts")));
}
Aggregations