From 3988fbb4b8e635d2d26b97cf7572d517c21f93fe Mon Sep 17 00:00:00 2001 From: Arjan Seijkens Date: Fri, 3 Jul 2020 15:29:51 +0200 Subject: [PATCH] Created a unit test, that MetaModel is unable to work with a document indexed by Elasticsearch which contains dots in its fieldnames. Note that this is actually caused by Elasticsearch, because the mapping returned for such a document by Elasticsearch doesn't match the source returned by Elasticsearch when getting the source of a search hit. (see https://github.com/elastic/elasticsearch-hadoop/issues/853 and related issues for more info on this). --- .../rest/ElasticSearchRestNestedDataIT.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/elasticsearch/rest/src/test/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestNestedDataIT.java b/elasticsearch/rest/src/test/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestNestedDataIT.java index 890cda77b..1265d619d 100644 --- a/elasticsearch/rest/src/test/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestNestedDataIT.java +++ b/elasticsearch/rest/src/test/java/org/apache/metamodel/elasticsearch/rest/ElasticSearchRestNestedDataIT.java @@ -38,6 +38,7 @@ import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.indices.CreateIndexRequest; +import org.elasticsearch.common.xcontent.XContentType; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -111,4 +112,38 @@ public void testNestedData() throws Exception { assertEquals("Main street 1, Newville", userValueMap.get("address")); } } + + @Test + public void testIndexOfDocumentWithDots() throws Exception { + final String document = + "{ \"user.fullname\": \"John Doe\", " + + "\"user.address\": \"Main street 1, Newville\", " + + "\"message\": \"This is what I have to say.\" }"; + + final IndexRequest indexRequest = new IndexRequest(INDEX_NAME).id("1"); + indexRequest.source(document, XContentType.JSON); + + client.index(indexRequest, RequestOptions.DEFAULT); + + final Table table = dataContext.getDefaultSchema().getTableByName(DEFAULT_TABLE_NAME); + + assertThat(table.getColumnNames(), containsInAnyOrder("_id", "message", "user")); + + dataContext.refreshSchemas(); + + try (final DataSet dataSet = dataContext + .query() + .from(DEFAULT_TABLE_NAME) + .select("user") + .and("message") + .execute()) { + assertEquals(ElasticSearchRestDataSet.class, dataSet.getClass()); + + assertTrue(dataSet.next()); + final Row row = dataSet.getRow(); + assertEquals("This is what I have to say.", row.getValue(table.getColumnByName("message"))); + + assertNotNull(row.getValue(table.getColumnByName("user"))); + } + } }