use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class SearchSortValuesTests method testFromXContent.
public void testFromXContent() throws IOException {
SearchSortValues sortValues = createTestItem();
XContentType xcontentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(sortValues, xcontentType, humanReadable);
SearchSortValues parsed;
try (XContentParser parser = createParser(xcontentType.xContent(), originalBytes)) {
// skip to the elements start array token, fromXContent advances from there if called
parser.nextToken();
parser.nextToken();
parser.nextToken();
parsed = SearchSortValues.fromXContent(parser);
parser.nextToken();
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertNull(parser.nextToken());
}
assertToXContentEquivalent(originalBytes, toXContent(parsed, xcontentType, humanReadable), xcontentType);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class NestedIdentityTests method testFromXContent.
public void testFromXContent() throws IOException {
NestedIdentity nestedIdentity = createTestItem(randomInt(3));
XContentType xcontentType = randomFrom(XContentType.values());
XContentBuilder builder = XContentFactory.contentBuilder(xcontentType);
if (randomBoolean()) {
builder.prettyPrint();
}
builder = nestedIdentity.innerToXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = createParser(builder);
NestedIdentity parsedNestedIdentity = NestedIdentity.fromXContent(parser);
assertEquals(nestedIdentity, parsedNestedIdentity);
assertNull(parser.nextToken());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType in project crate by crate.
the class JsonXContentGenerator method writeRawField.
@Override
public void writeRawField(String name, InputStream content) throws IOException {
if (content.markSupported() == false) {
// needed for the XContentFactory.xContentType call
content = new BufferedInputStream(content);
}
XContentType contentType = XContentFactory.xContentType(content);
if (contentType == null) {
throw new IllegalArgumentException("Can't write raw bytes whose xcontent-type can't be guessed");
}
writeRawField(name, content, contentType);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType in project crate by crate.
the class ColumnPolicyIntegrationTest method testDynamicPartitionedTable.
@Test
public void testDynamicPartitionedTable() throws Exception {
execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='dynamic', number_of_replicas=0)");
ensureYellow();
GetIndexTemplatesResponse templateResponse = client().admin().indices().prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "numbers")).execute().actionGet();
assertThat(templateResponse.getIndexTemplates().size(), is(1));
IndexTemplateMetadata template = templateResponse.getIndexTemplates().get(0);
CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(mappingStr, is(notNullValue()));
Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false);
@SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(mapping.get("dynamic")), is("true"));
execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
execute("refresh table numbers");
Map<String, Object> sourceMap = getSourceMap(new PartitionName(new RelationName("doc", "numbers"), Collections.singletonList("true")).asIndexName());
assertThat(String.valueOf(sourceMap.get("dynamic")), is("true"));
execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[] { 28, true, false, true });
ensureYellow();
execute("refresh table numbers");
waitForMappingUpdateOnAll("numbers", "perfect");
execute("select * from numbers order by num");
assertThat(response.rowCount(), is(2L));
assertThat(response.cols(), arrayContaining("num", "odd", "prime", "perfect"));
assertThat(TestingHelpers.printedTable(response.rows()), is("6| true| false| NULL\n" + "28| true| false| true\n"));
execute("update numbers set prime=true, changed='2014-10-23T10:20', author='troll' where num=28");
assertThat(response.rowCount(), is(1L));
waitForMappingUpdateOnAll("numbers", "changed");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType in project crate by crate.
the class ColumnPolicyIntegrationTest method testStrictPartitionedTableUpdate.
@Test
public void testStrictPartitionedTableUpdate() throws Exception {
execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)");
ensureYellow();
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "numbers")).execute().actionGet();
assertThat(response.getIndexTemplates().size(), is(1));
IndexTemplateMetadata template = response.getIndexTemplates().get(0);
CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(mappingStr, is(notNullValue()));
Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false);
@SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(decodeMappingValue(mapping.get("dynamic")), is(ColumnPolicy.STRICT));
execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
execute("refresh table numbers");
Map<String, Object> sourceMap = getSourceMap(new PartitionName(new RelationName("doc", "numbers"), Arrays.asList("true")).asIndexName());
assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.STRICT));
assertThrowsMatches(() -> execute("update numbers set num=?, perfect=? where num=6", new Object[] { 28, true }), isSQLError(is("Column perfect unknown"), UNDEFINED_COLUMN, NOT_FOUND, 4043));
}
Aggregations