Skip to content

Commit

Permalink
Support mixed case fields in Elasticsearch
Browse files Browse the repository at this point in the history
Preserve the original (mixed-case) column name for further requests
to Elasticsearch instead of relying on the name from ColumnMetadata,
which is lower-cased.
  • Loading branch information
martint committed Jun 2, 2019
1 parent 486fe07 commit 4217df6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Expand Up @@ -250,6 +250,7 @@ private List<ColumnMetadata> buildMetadata(List<ElasticsearchColumn> columns)
List<ColumnMetadata> result = new ArrayList<>();
for (ElasticsearchColumn column : columns) {
Map<String, Object> properties = new HashMap<>();
properties.put("originalColumnName", column.getName());
properties.put("jsonPath", column.getJsonPath());
properties.put("jsonType", column.getJsonType());
properties.put("isList", column.isList());
Expand Down
Expand Up @@ -113,7 +113,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
int position = ordinalPosition == -1 ? index : ordinalPosition;
columnHandles.put(column.getName(),
new ElasticsearchColumnHandle(
column.getName(),
String.valueOf(properties.get("originalColumnName")),
column.getType(),
String.valueOf(properties.get("jsonPath")),
String.valueOf(properties.get("jsonType")),
Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package io.prestosql.elasticsearch;

import com.google.common.collect.ImmutableMap;
import com.google.common.io.Closer;
import io.airlift.tpch.TpchTable;
import io.prestosql.testing.MaterializedResult;
Expand All @@ -31,6 +32,7 @@
import static io.prestosql.testing.MaterializedResult.resultBuilder;
import static io.prestosql.testing.assertions.Assert.assertEquals;
import static java.lang.String.format;
import static org.elasticsearch.client.Requests.refreshRequest;

public class TestElasticsearchIntegrationSmokeTest
extends AbstractTestIntegrationSmokeTest
Expand Down Expand Up @@ -90,4 +92,32 @@ public void testDescribeTable()
.row("comment", "varchar", "", "").build();
assertEquals(actualResult, expectedColumns, format("%s != %s", actualResult, expectedColumns));
}

@Test
public void testMixedCaseFields()
{
// add an entry to the index
embeddedElasticsearchNode.getClient()
.prepareIndex("person", "doc")
.setSource(ImmutableMap.<String, Object>builder()
.put("Name", "John")
.put("Age", 20)
.build())
.get();

// ensure the index is up to date
embeddedElasticsearchNode.getClient()
.admin()
.indices()
.refresh(refreshRequest("person"))
.actionGet();

assertQuery(
"SELECT Name, Age FROM test.person",
"VALUES ('John', 20)");

assertQuery(
"SELECT name, age FROM test.person",
"VALUES ('John', 20)");
}
}
@@ -0,0 +1,25 @@
{
"tableName": "person",
"schemaName": "test",
"host": "localhost",
"port": "9300",
"clusterName": "test",
"index": "person",
"type": "doc",
"columns": [
{
"name": "Name",
"type": "varchar",
"jsonPath": "Name",
"jsonType": "varchar",
"ordinalPosition": "0"
},
{
"name": "Age",
"type": "integer",
"jsonPath": "Age",
"jsonType": "integer",
"ordinalPosition": "1"
}
]
}

0 comments on commit 4217df6

Please sign in to comment.