Skip to content

Commit

Permalink
Add test for column name containing special characters in Elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
striderarun authored and martint committed Jan 17, 2025
1 parent 7250b50 commit c2cb00b
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
import java.util.List;
import java.util.Map;

import static io.trino.spi.StandardErrorCode.INVALID_COLUMN_REFERENCE;
import static io.trino.spi.type.DoubleType.DOUBLE;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.testing.MaterializedResult.resultBuilder;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -298,6 +300,23 @@ public void testNestedFields()
.matches("VALUES (VARCHAR 'nestfield', BIGINT '32', VARCHAR 'valueb')");
}

@Test
public void testFieldNameWithSpecialCharacters()
throws IOException
{
String index = "field_name_with_special_characters_" + randomNameSuffix();
index(index, ImmutableMap.<String, Object>builder()
.put("with$sign", 55)
.put("nested", ImmutableMap.<String, Object>builder()
.put("with$sign", "few bucks")
.buildOrThrow())
.buildOrThrow());

assertThat(query("SELECT \"with$sign\", nested.\"with$sign\" FROM " + index))
.skippingTypesCheck()
.matches("VALUES (CAST(55 AS BIGINT), 'few bucks')");
}

@Test
public void testNameConflict()
throws IOException
Expand Down Expand Up @@ -1003,7 +1022,23 @@ public void testNestedVariants()
throws IOException
{
String indexName = "nested_variants";
@Language("JSON")
String properties =
"""
{
"properties": {
"a": {
"properties": {
"b.c": {
"type": "text"
}
}
}
}
}
""";

createIndex(indexName, properties);
index(indexName,
ImmutableMap.of("a",
ImmutableMap.of("b",
Expand All @@ -1025,6 +1060,10 @@ public void testNestedVariants()

assertThat(query("SELECT a.b.c FROM nested_variants"))
.matches("VALUES VARCHAR 'value1', VARCHAR 'value2', VARCHAR 'value3', VARCHAR 'value4'");

assertTrinoExceptionThrownBy(() -> computeActual("SELECT a.\"b.c\" FROM nested_variants"))
.hasErrorCode(INVALID_COLUMN_REFERENCE)
.hasMessageContaining("Column reference 'a.b.c' is invalid");
}

@Test
Expand Down

0 comments on commit c2cb00b

Please sign in to comment.