Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug with ElasticSearchQueryBuilder, Column Name are not preserving case sensivity #12791

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public SearchRequestBuilder buildScrollSearchRequest()
{
String indices = index != null && !index.isEmpty() ? index : "_all";
List<String> fields = columns.stream()
.map(ElasticsearchColumnHandle::getColumnName)
.map(ElasticsearchColumnHandle::getColumnJsonPath)
.collect(toList());
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indices)
.setTypes(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static com.facebook.presto.elasticsearch.ElasticsearchQueryRunner.createElasticsearchQueryRunner;
import static com.facebook.presto.elasticsearch.EmbeddedElasticsearchNode.createEmbeddedElasticsearchNode;
import static com.facebook.presto.spi.type.BigintType.BIGINT;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
import static com.facebook.presto.testing.assertions.Assert.assertEquals;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static org.elasticsearch.client.Requests.refreshRequest;

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

@Test
public void testCaseSensitiveField()
{
String indexName = "machine";
String tableName = "telemetry.Machine";

Map<String, Object> source = new HashMap<>();
source.put("ProductionCount", 32L);
source.put("Name", "A Big Machine");

embeddedElasticsearchNode.getClient().prepareIndex(indexName.toLowerCase(ENGLISH), "doc").setSource(source).get();
embeddedElasticsearchNode.getClient().admin().indices().refresh(refreshRequest(indexName)).actionGet();

MaterializedResult actualColumns = computeActual("SELECT name, ProductionCount FROM " + tableName).toTestTypes();
MaterializedResult.Builder builder = resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, BIGINT);
for (MaterializedRow row : actualColumns.getMaterializedRows()) {
builder.row(row.getField(0), row.getField(1));
}

MaterializedResult actualResult = builder.build();
builder = resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, BIGINT);
MaterializedResult expectedColumns = builder
.row("A Big Machine", 32L).build();
assertEquals(actualResult, expectedColumns, format("%s != %s", actualResult, expectedColumns));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"tableName": "machine",
"schemaName": "telemetry",
"host": "localhost",
"port": "9300",
"clusterName": "test",
"index": "machine",
"type": "doc",
"columns": [

{
"name": "Name",
"type": "varchar",
"jsonPath": "Name",
"jsonType": "varchar",
"ordinalPosition": "0"
},
{
"name": "ProductionCount",
"type": "bigint",
"jsonPath": "ProductionCount",
"jsonType": "bigint",
"ordinalPosition": "1"
}
]
}