From 117e6f0522aaf4c1946f1737078fa13c23615311 Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Thu, 22 Feb 2024 10:17:42 -0800 Subject: [PATCH] Use text blocks for multiline strings --- .../BaseElasticsearchConnectorTest.java | 1182 +++++++++-------- 1 file changed, 613 insertions(+), 569 deletions(-) diff --git a/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/BaseElasticsearchConnectorTest.java b/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/BaseElasticsearchConnectorTest.java index dea59c718841..313342b5dfe3 100644 --- a/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/BaseElasticsearchConnectorTest.java +++ b/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/BaseElasticsearchConnectorTest.java @@ -213,13 +213,14 @@ public void testNullPredicate() { String indexName = "null_predicate1"; @Language("JSON") - String properties = "" + - "{" + - " \"properties\":{" + - " \"null_keyword\": { \"type\": \"keyword\" }," + - " \"custkey\": { \"type\": \"keyword\" }" + - " }" + - "}"; + String properties = """ + { + "properties": { + "null_keyword": { "type": "keyword" }, + "custkey": { "type": "keyword" } + } + } + """; createIndex(indexName, properties); index(indexName, ImmutableMap.builder() .put("null_keyword", 32) @@ -241,13 +242,14 @@ public void testNullPredicate() assertQuery("SELECT custkey FROM null_predicate1 WHERE null_keyword = '32' OR null_keyword IS NOT NULL", "VALUES (1301)"); indexName = "null_predicate2"; - properties = "" + - "{" + - " \"properties\":{" + - " \"null_keyword\": { \"type\": \"keyword\" }," + - " \"custkey\": { \"type\": \"keyword\" }" + - " }" + - "}"; + properties = """ + { + "properties": { + "null_keyword": { "type": "keyword" }, + "custkey": { "type": "keyword" } + } + } + """; createIndex(indexName, properties); index(indexName, ImmutableMap.of("custkey", 1301)); @@ -310,83 +312,84 @@ public void testArrayFields() String indexName = "test_arrays"; @Language("JSON") - String mapping = "" + - "{" + - " \"_meta\": {" + - " \"trino\": {" + - " \"a\": {" + - " \"b\": {" + - " \"y\": {" + - " \"isArray\": true" + - " }" + - " }" + - " }," + - " \"c\": {" + - " \"f\": {" + - " \"g\": {" + - " \"isArray\": true" + - " }," + - " \"isArray\": true" + - " }" + - " }," + - " \"j\": {" + - " \"isArray\": true" + - " }," + - " \"k\": {" + - " \"isArray\": true" + - " }" + - " }" + - " }," + - " \"properties\":{" + - " \"a\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"b\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"x\": {" + - " \"type\": \"integer\"" + - " }," + - " \"y\": {" + - " \"type\": \"keyword\"" + - " }" + - " } " + - " }" + - " }" + - " }," + - " \"c\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"d\": {" + - " \"type\": \"keyword\"" + - " }," + - " \"e\": {" + - " \"type\": \"keyword\"" + - " }," + - " \"f\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"g\": {" + - " \"type\": \"integer\"" + - " }," + - " \"h\": {" + - " \"type\": \"integer\"" + - " }" + - " } " + - " }" + - " }" + - " }," + - " \"i\": {" + - " \"type\": \"long\"" + - " }," + - " \"j\": {" + - " \"type\": \"long\"" + - " }," + - " \"k\": {" + - " \"type\": \"long\"" + - " }" + - " }" + - "}"; + String mapping = """ + { + "_meta": { + "trino": { + "a": { + "b": { + "y": { + "isArray": true + } + } + }, + "c": { + "f": { + "g": { + "isArray": true + }, + "isArray": true + } + }, + "j": { + "isArray": true + }, + "k": { + "isArray": true + } + } + }, + "properties":{ + "a": { + "type": "object", + "properties": { + "b": { + "type": "object", + "properties": { + "x": { + "type": "integer" + }, + "y": { + "type": "keyword" + } + }\s + } + } + }, + "c": { + "type": "object", + "properties": { + "d": { + "type": "keyword" + }, + "e": { + "type": "keyword" + }, + "f": { + "type": "object", + "properties": { + "g": { + "type": "integer" + }, + "h": { + "type": "integer" + } + }\s + } + } + }, + "i": { + "type": "long" + }, + "j": { + "type": "long" + }, + "k": { + "type": "long" + } + } + } + """; createIndex(indexName, mapping); @@ -438,89 +441,90 @@ public void testAsRawJson() String indexName = "raw_json_" + randomNameSuffix(); @Language("JSON") - String mapping = "" + - "{" + - " \"_meta\": {" + - " \"trino\": {" + - " \"es_object\": {" + - " \"array_of_string_arrays\": {" + - " \"asRawJson\": true" + - " }," + - " \"arrayOfIntArrays\": {" + - " \"asRawJson\": true" + - " }" + - " }," + - " \"es_array_object\": {" + - " \"isArray\": true," + - " \"array_of_string_arrays\": {" + - " \"asRawJson\": true" + - " }," + - " \"arrayOfIntArrays\": {" + - " \"asRawJson\": true" + - " }" + - " }," + - " \"es_raw_object\": {" + - " \"asRawJson\": true," + - " \"array_of_string_arrays\": {" + - " \"isArray\": true" + - " }," + - " \"arrayOfIntArrays\": {" + - " \"isArray\": true" + - " }" + - " }," + - " \"array_of_string_arrays\": {" + - " \"asRawJson\": true" + - " }," + - " \"array_of_long_arrays\": {" + - " \"asRawJson\": true" + - " }" + - " }" + - " }," + - " \"properties\": {" + - " \"es_object\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"array_of_string_arrays\": {" + - " \"type\": \"keyword\"" + - " }," + - " \"arrayOfIntArrays\": {" + - " \"type\": \"integer\"" + - " }" + - " }" + - " }," + - " \"es_array_object\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"array_of_string_arrays\": {" + - " \"type\": \"keyword\"" + - " }," + - " \"arrayOfIntArrays\": {" + - " \"type\": \"integer\"" + - " }" + - " }" + - " }," + - " \"es_raw_object\": {" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"array_of_string_arrays\": {" + - " \"type\": \"keyword\"" + - " }," + - " \"arrayOfIntArrays\": {" + - " \"type\": \"integer\"" + - " }" + - " }" + - " }," + - " \"array_of_string_arrays\": {" + - " \"type\": \"text\"" + - " }," + - " \"array_of_long_arrays\": {" + - " \"type\": \"long\"" + - " }," + - " \"order_field\": {" + - " \"type\": \"integer\"" + - " }" + - " }" + - "}"; + String mapping = """ + { + "_meta": { + "trino": { + "es_object": { + "array_of_string_arrays": { + "asRawJson": true + }, + "arrayOfIntArrays": { + "asRawJson": true + } + }, + "es_array_object": { + "isArray": true, + "array_of_string_arrays": { + "asRawJson": true + }, + "arrayOfIntArrays": { + "asRawJson": true + } + }, + "es_raw_object": { + "asRawJson": true, + "array_of_string_arrays": { + "isArray": true + }, + "arrayOfIntArrays": { + "isArray": true + } + }, + "array_of_string_arrays": { + "asRawJson": true + }, + "array_of_long_arrays": { + "asRawJson": true + } + } + }, + "properties": { + "es_object": { + "type": "object", + "properties": { + "array_of_string_arrays": { + "type": "keyword" + }, + "arrayOfIntArrays": { + "type": "integer" + } + } + }, + "es_array_object": { + "type": "object", + "properties": { + "array_of_string_arrays": { + "type": "keyword" + }, + "arrayOfIntArrays": { + "type": "integer" + } + } + }, + "es_raw_object": { + "type": "object", + "properties": { + "array_of_string_arrays": { + "type": "keyword" + }, + "arrayOfIntArrays": { + "type": "integer" + } + } + }, + "array_of_string_arrays": { + "type": "text" + }, + "array_of_long_arrays": { + "type": "long" + }, + "order_field": { + "type": "integer" + } + } + } + """; createIndex(indexName, mapping); @@ -604,17 +608,19 @@ public void testAsRawJson() .put("order_field", 2) .buildOrThrow()); - MaterializedResult rows = computeActual("" + - "SELECT " + - "json_extract(array_of_string_arrays, '$[0][0]'), " + - "json_extract(array_of_string_arrays, '$[0][1]'), " + - "array_of_string_arrays, " + - "json_extract(array_of_long_arrays, '$[0]'), " + - "try(json_extract(array_of_long_arrays, '$[1][0]')), " + - "try(json_extract(array_of_long_arrays, '$[1][1]')), " + - "array_of_long_arrays " + - "FROM " + indexName + " " + - "ORDER BY order_field"); + MaterializedResult rows = computeActual( + """ + SELECT + json_extract(array_of_string_arrays, '$[0][0]'), + json_extract(array_of_string_arrays, '$[0][1]'), + array_of_string_arrays, + json_extract(array_of_long_arrays, '$[0]'), + try(json_extract(array_of_long_arrays, '$[1][0]')), + try(json_extract(array_of_long_arrays, '$[1][1]')), + array_of_long_arrays + FROM %s + ORDER BY order_field + """.formatted(indexName)); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row("\"abc\"", "\"def\"", "[[\"abc\",\"def\"]]", "123", "234", "345", "[123,[234,345]]") @@ -623,17 +629,19 @@ public void testAsRawJson() assertThat(rows.getMaterializedRows()).isEqualTo(expected.getMaterializedRows()); - MaterializedResult nestedRows = computeActual("" + - "SELECT " + - "json_extract(es_object.array_of_string_arrays, '$[0][0]'), " + - "json_extract(es_object.array_of_string_arrays, '$[0][1]'), " + - "es_object.array_of_string_arrays, " + - "json_extract(es_object.arrayOfIntArrays, '$[0]'), " + - "try(json_extract(es_object.arrayOfIntArrays, '$[1][0]')), " + - "try(json_extract(es_object.arrayOfIntArrays, '$[1][1]')), " + - "es_object.arrayOfIntArrays " + - "FROM " + indexName + " " + - "ORDER BY order_field"); + MaterializedResult nestedRows = computeActual( + """ + SELECT + json_extract(es_object.array_of_string_arrays, '$[0][0]'), + json_extract(es_object.array_of_string_arrays, '$[0][1]'), + es_object.array_of_string_arrays, + json_extract(es_object.arrayOfIntArrays, '$[0]'), + try(json_extract(es_object.arrayOfIntArrays, '$[1][0]')), + try(json_extract(es_object.arrayOfIntArrays, '$[1][1]')), + es_object.arrayOfIntArrays + FROM %s + ORDER BY order_field + """.formatted(indexName)); MaterializedResult nestedExpected = resultBuilder(getSession(), nestedRows.getTypes()) .row("\"abc\"", "\"def\"", "[[\"abc\",\"def\"]]", "123", "234", "345", "[123,[234,345]]") @@ -642,17 +650,19 @@ public void testAsRawJson() assertThat(nestedRows.getMaterializedRows()).isEqualTo(nestedExpected.getMaterializedRows()); - MaterializedResult arrayRows = computeActual("" + - "SELECT " + - "json_extract(es_array_object[1].array_of_string_arrays, '$[0][0]'), " + - "json_extract(es_array_object[1].array_of_string_arrays, '$[0][1]'), " + - "es_array_object[1].array_of_string_arrays, " + - "json_extract(es_array_object[1].arrayOfIntArrays, '$[0]'), " + - "try(json_extract(es_array_object[1].arrayOfIntArrays, '$[1][0]')), " + - "try(json_extract(es_array_object[1].arrayOfIntArrays, '$[1][1]')), " + - "es_array_object[1].arrayOfIntArrays " + - "FROM " + indexName + " " + - "ORDER BY order_field"); + MaterializedResult arrayRows = computeActual( + """ + SELECT + json_extract(es_array_object[1].array_of_string_arrays, '$[0][0]'), + json_extract(es_array_object[1].array_of_string_arrays, '$[0][1]'), + es_array_object[1].array_of_string_arrays, + json_extract(es_array_object[1].arrayOfIntArrays, '$[0]'), + try(json_extract(es_array_object[1].arrayOfIntArrays, '$[1][0]')), + try(json_extract(es_array_object[1].arrayOfIntArrays, '$[1][1]')), + es_array_object[1].arrayOfIntArrays + FROM %s + ORDER BY order_field + """.formatted(indexName)); MaterializedResult arrayExpected = resultBuilder(getSession(), arrayRows.getTypes()) .row("\"abc\"", "\"def\"", "[[\"abc\",\"def\"]]", "123", "234", "345", "[123,[234,345]]") @@ -661,17 +671,19 @@ public void testAsRawJson() assertThat(arrayRows.getMaterializedRows()).isEqualTo(arrayExpected.getMaterializedRows()); - MaterializedResult rawRows = computeActual("" + - "SELECT " + - "json_extract(es_raw_object, '$.array_of_string_arrays[0][0]'), " + - "json_extract(es_raw_object, '$.array_of_string_arrays[0][1]'), " + - "json_extract(es_raw_object, '$.array_of_string_arrays'), " + - "json_extract(es_raw_object, '$.arrayOfIntArrays[0]'), " + - "try(json_extract(es_raw_object, '$.arrayOfIntArrays[1][0]')), " + - "try(json_extract(es_raw_object, '$.arrayOfIntArrays[1][1]')), " + - "json_extract(es_raw_object, '$.arrayOfIntArrays') " + - "FROM " + indexName + " " + - "ORDER BY order_field"); + MaterializedResult rawRows = computeActual( + """ + SELECT + json_extract(es_raw_object, '$.array_of_string_arrays[0][0]'), + json_extract(es_raw_object, '$.array_of_string_arrays[0][1]'), + json_extract(es_raw_object, '$.array_of_string_arrays'), + json_extract(es_raw_object, '$.arrayOfIntArrays[0]'), + try(json_extract(es_raw_object, '$.arrayOfIntArrays[1][0]')), + try(json_extract(es_raw_object, '$.arrayOfIntArrays[1][1]')), + json_extract(es_raw_object, '$.arrayOfIntArrays') + FROM %s + ORDER BY order_field + """.formatted(indexName)); MaterializedResult rawRowsExpected = resultBuilder(getSession(), rawRows.getTypes()) .row("\"abc\"", "\"def\"", "[[\"abc\",\"def\"]]", "123", "234", "345", "[123,[234,345]]") @@ -688,66 +700,66 @@ public void testAsRawJsonForAllPrimitiveTypes() String indexName = "raw_json_primitive_" + randomNameSuffix(); @Language("JSON") - String mapping = "" + - "{" + - " \"_meta\": {" + - " \"trino\": {" + - " \"es_binary\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_boolean\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_long\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_integer\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_short\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_byte\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_double\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_float\": {" + - " \"asRawJson\": true" + - " }" + - " }" + - " }," + - " \"properties\": {" + - " \"es_binary\": {" + - " \"type\": \"binary\"" + - " }," + - " \"es_boolean\": {" + - " \"type\": \"boolean\"" + - " }," + - " \"es_long\": {" + - " \"type\": \"long\"" + - " }," + - " \"es_integer\": {" + - " \"type\": \"integer\"" + - " }," + - " \"es_short\": {" + - " \"type\": \"short\"" + - " }," + - " \"es_byte\": {" + - " \"type\": \"byte\"" + - " }," + - " \"es_double\": {" + - " \"type\": \"double\"" + - " }," + - " \"es_float\": {" + - " \"type\": \"float\"" + - " }," + - " \"order_field\": {" + - " \"type\": \"integer\"" + - " }" + - " }" + - "}"; + String mapping = """ + { + "_meta": { + "trino": { + "es_binary": { + "asRawJson": true + }, + "es_boolean": { + "asRawJson": true + }, + "es_long": { + "asRawJson": true + }, + "es_integer": { + "asRawJson": true + }, + "es_short": { + "asRawJson": true + }, + "es_byte": { + "asRawJson": true + }, + "es_double": { + "asRawJson": true + }, + "es_float": { + "asRawJson": true + } + } + }, + "properties": { + "es_binary": { + "type": "binary" + }, + "es_boolean": { + "type": "boolean" + }, + "es_long": { + "type": "long" + }, + "es_integer": { + "type": "integer" + }, + "es_short": { + "type": "short" + }, + "es_byte": { + "type": "byte" + }, + "es_double": { + "type": "double" + }, + "es_float": { + "type": "float" + }, + "order_field": { + "type": "integer" + } + } + }"""; createIndex(indexName, mapping); @@ -763,18 +775,20 @@ public void testAsRawJsonForAllPrimitiveTypes() .put("order_field", 1) .buildOrThrow()); - MaterializedResult rows = computeActual("" + - "SELECT " + - "es_binary, " + - "es_boolean, " + - "es_long, " + - "es_integer, " + - "es_short, " + - "es_byte, " + - "es_double, " + - "es_float " + - "FROM " + indexName + " " + - "ORDER BY order_field"); + MaterializedResult rows = computeActual( + """ + SELECT + es_binary, + es_boolean, + es_long, + es_integer, + es_short, + es_byte, + es_double, + es_float + FROM %s + ORDER BY order_field + """.formatted(indexName)); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row("\"dGVzdA==\"", "true", "123", "123", "123", "123", "123.0", "123.0") @@ -794,33 +808,33 @@ public void testAsRawJsonCases() String indexName = "raw_json_cases_" + randomNameSuffix(); @Language("JSON") - String mapping = "" + - "{" + - " \"_meta\": {" + - " \"trino\": {" + - " \"es_binary\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_boolean\": {" + - " \"asRawJson\": true" + - " }," + - " \"es_timestamp\": {" + - " \"asRawJson\": true" + - " }" + - " }" + - " }," + - " \"properties\": {" + - " \"es_binary\": {" + - " \"type\": \"binary\"" + - " }," + - " \"es_boolean\": {" + - " \"type\": \"boolean\"" + - " }," + - " \"es_timestamp\": {" + - " \"type\": \"date\"" + - " }" + - " }" + - "}"; + String mapping = """ + { + "_meta": { + "trino": { + "es_binary": { + "asRawJson": true + }, + "es_boolean": { + "asRawJson": true + }, + "es_timestamp": { + "asRawJson": true + } + } + }, + "properties": { + "es_binary": { + "type": "binary" + }, + "es_boolean": { + "type": "boolean" + }, + "es_timestamp": { + "type": "date" + } + } + }"""; createIndex(indexName, mapping); @@ -830,12 +844,14 @@ public void testAsRawJsonCases() .put("es_timestamp", 123) .buildOrThrow()); - MaterializedResult rows = computeActual("" + - "SELECT " + - "es_binary, " + - "es_boolean, " + - "es_timestamp " + - "FROM " + indexName); + MaterializedResult rows = computeActual( + """ + SELECT + es_binary, + es_boolean, + es_timestamp + FROM %s + """.formatted(indexName)); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row("\"dGVzdA==\"", "true", "123") @@ -855,22 +871,23 @@ public void testAsRawJsonAndIsArraySameFieldException() String indexName = "raw_json_array_exception" + randomNameSuffix(); @Language("JSON") - String mapping = "" + - "{" + - " \"_meta\": {" + - " \"trino\": {" + - " \"array_raw_field\": {" + - " \"asRawJson\": true," + - " \"isArray\": true" + - " }" + - " }" + - " }," + - " \"properties\": {" + - " \"array_raw_field\": {" + - " \"type\": \"text\"" + - " }" + - " }" + - "}"; + String mapping = """ + { + "_meta": { + "trino": { + "array_raw_field": { + "asRawJson": true, + "isArray": true + } + } + }, + "properties": { + "array_raw_field": { + "type": "text" + } + } + } + """; createIndex(indexName, mapping); @@ -891,21 +908,22 @@ public void testMixedArray() String indexName = "test_mixed_arrays"; @Language("JSON") - String mapping = "" + - "{" + - " \"_meta\": {" + - " \"trino\": {" + - " \"a\": {" + - " \"isArray\": true" + - " }" + - " }" + - " }," + - " \"properties\": {" + - " \"a\": {" + - " \"type\": \"keyword\"" + - " }" + - " }" + - "}"; + String mapping = """ + { + "_meta": { + "trino": { + "a": { + "isArray": true + } + } + }, + "properties": { + "a": { + "type": "keyword" + } + } + } + """; createIndex(indexName, mapping); @@ -927,18 +945,19 @@ public void testEmptyNumericFields() String indexName = "emptynumeric"; @Language("JSON") - String mapping = "" + - "{" + - " \"properties\": { " + - " \"byte_column\": {\"type\": \"byte\"}," + - " \"short_column\": {\"type\": \"short\"}," + - " \"integer_column\": {\"type\": \"integer\"}," + - " \"long_column\": {\"type\": \"long\"}," + - " \"float_column\": {\"type\": \"float\"}," + - " \"scaled_float_column\": {\"type\": \"scaled_float\", \"scaling_factor\": 100}," + - " \"double_column\": {\"type\": \"double\"}" + - " }" + - "}"; + String mapping = """ + { + "properties": { + "byte_column": {"type": "byte"}, + "short_column": {"type": "short"}, + "integer_column": {"type": "integer"}, + "long_column": {"type": "long"}, + "float_column": {"type": "float"}, + "scaled_float_column": {"type": "scaled_float", "scaling_factor": 100}, + "double_column": {"type": "double"} + } + } + """; createIndex(indexName, mapping); index(indexName, ImmutableMap.builder() @@ -1012,13 +1031,14 @@ public void testLike() String indexName = "like_test"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"keyword_column\": { \"type\": \"keyword\" }," + - " \"text_column\": { \"type\": \"text\" }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "keyword_column": { "type": "keyword" }, + "text_column": { "type": "text" } + } + } + """; createIndex(indexName, mappings); @@ -1130,23 +1150,24 @@ public void testDataTypes() String indexName = "types"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"boolean_column\": { \"type\": \"boolean\" }," + - " \"float_column\": { \"type\": \"float\" }," + - " \"double_column\": { \"type\": \"double\" }," + - " \"integer_column\": { \"type\": \"integer\" }," + - " \"long_column\": { \"type\": \"long\" }," + - " \"keyword_column\": { \"type\": \"keyword\" }," + - " \"text_column\": { \"type\": \"text\" }," + - " \"binary_column\": { \"type\": \"binary\" }," + - " \"timestamp_column\": { \"type\": \"date\" }," + - " \"ipv4_column\": { \"type\": \"ip\" }," + - " \"ipv6_column\": { \"type\": \"ip\" }," + - " \"scaled_float_column\": { \"type\": \"scaled_float\", \"scaling_factor\": 100 }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "boolean_column": { "type": "boolean" }, + "float_column": { "type": "float" }, + "double_column": { "type": "double" }, + "integer_column": { "type": "integer" }, + "long_column": { "type": "long" }, + "keyword_column": { "type": "keyword" }, + "text_column": { "type": "text" }, + "binary_column": { "type": "binary" }, + "timestamp_column": { "type": "date" }, + "ipv4_column": { "type": "ip" }, + "ipv6_column": { "type": "ip" }, + "scaled_float_column": { "type": "scaled_float", "scaling_factor": 100 } + } + } + """; createIndex(indexName, mappings); @@ -1165,21 +1186,23 @@ public void testDataTypes() .put("scaled_float_column", 123456.78d) .buildOrThrow()); - MaterializedResult rows = computeActual("" + - "SELECT " + - "boolean_column, " + - "float_column, " + - "double_column, " + - "integer_column, " + - "long_column, " + - "keyword_column, " + - "text_column, " + - "binary_column, " + - "timestamp_column, " + - "ipv4_column, " + - "ipv6_column, " + - "scaled_float_column " + - "FROM types"); + MaterializedResult rows = computeActual( + """ + SELECT + boolean_column, + float_column, + double_column, + integer_column, + long_column, + keyword_column, + text_column, + binary_column, + timestamp_column, + ipv4_column, + ipv6_column, + scaled_float_column + FROM types + """); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row( @@ -1207,13 +1230,14 @@ public void testTableWithUnsupportedTypes() String indexName = "unsupported_types"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"long_column\": { \"type\": \"long\" }," + - " \"unsupported_type\": { \"type\": \"completion\"}" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "long_column": { "type": "long" }, + "unsupported_type": { "type": "completion"} + } + } + """; createIndex(indexName, mappings); @@ -1237,12 +1261,13 @@ public void testBoolean() String indexName = "booleans"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"boolean_column\": { \"type\": \"boolean\" }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "boolean_column": { "type": "boolean" } + } + } + """; createIndex(indexName, mappings); @@ -1276,12 +1301,13 @@ public void testTimestamps() String indexName = "timestamps"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"timestamp_column\": { \"type\": \"date\" }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "timestamp_column": { "type": "date" } + } + } + """; createIndex(indexName, mappings); @@ -1312,16 +1338,17 @@ public void testNestedTimestamps() String indexName = "nested_timestamps"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\":{" + - " \"field\": {" + - " \"properties\": {" + - " \"timestamp_column\": { \"type\": \"date\" }" + - " }" + - " }" + - " }" + - "}"; + String mappings = """ + { + "properties":{ + "field": { + "properties": { + "timestamp_column": { "type": "date" } + } + } + } + } + """; createIndex(indexName, mappings); @@ -1343,13 +1370,14 @@ public void testScaledFloat() String indexName = "scaled_float_type"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"text_column\": { \"type\": \"text\" }," + - " \"scaled_float_column\": { \"type\": \"scaled_float\", \"scaling_factor\": 100 }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "text_column": { "type": "text" }, + "scaled_float_column": { "type": "scaled_float", "scaling_factor": 100 } + } + } + """; createIndex(indexName, mappings); @@ -1387,15 +1415,16 @@ public void testCoercions() String indexName = "coercions"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"float_column\": { \"type\": \"float\" }," + - " \"double_column\": { \"type\": \"double\" }," + - " \"integer_column\": { \"type\": \"integer\" }," + - " \"long_column\": { \"type\": \"long\" }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "float_column": { "type": "float" }, + "double_column": { "type": "double" }, + "integer_column": { "type": "integer" }, + "long_column": { "type": "long" } + } + } + """; createIndex(indexName, mappings); @@ -1406,13 +1435,15 @@ public void testCoercions() .put("long_column", "1") .buildOrThrow()); - MaterializedResult rows = computeActual("" + - "SELECT " + - "float_column, " + - "double_column, " + - "integer_column, " + - "long_column " + - "FROM coercions"); + MaterializedResult rows = computeActual( + """ + SELECT + float_column, + double_column, + integer_column, + long_column + FROM coercions + """); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row(1.0f, 1.0d, 1, 1L) @@ -1428,22 +1459,23 @@ public void testFilters() String indexName = "filter_pushdown"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"boolean_column\": { \"type\": \"boolean\" }," + - " \"float_column\": { \"type\": \"float\" }," + - " \"double_column\": { \"type\": \"double\" }," + - " \"integer_column\": { \"type\": \"integer\" }," + - " \"long_column\": { \"type\": \"long\" }," + - " \"keyword_column\": { \"type\": \"keyword\" }," + - " \"text_column\": { \"type\": \"text\" }," + - " \"binary_column\": { \"type\": \"binary\" }," + - " \"timestamp_column\": { \"type\": \"date\" }," + - " \"ipv4_column\": { \"type\": \"ip\" }," + - " \"ipv6_column\": { \"type\": \"ip\" }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "boolean_column": { "type": "boolean" }, + "float_column": { "type": "float" }, + "double_column": { "type": "double" }, + "integer_column": { "type": "integer" }, + "long_column": { "type": "long" }, + "keyword_column": { "type": "keyword" }, + "text_column": { "type": "text" }, + "binary_column": { "type": "binary" }, + "timestamp_column": { "type": "date" }, + "ipv4_column": { "type": "ip" }, + "ipv6_column": { "type": "ip" } + } + } + """; createIndex(indexName, mappings); @@ -1588,26 +1620,27 @@ public void testDataTypesNested() String indexName = "types_nested"; @Language("JSON") - String properties = "" + - "{" + - " \"properties\":{" + - " \"field\": {" + - " \"properties\": {" + - " \"boolean_column\": { \"type\": \"boolean\" }," + - " \"float_column\": { \"type\": \"float\" }," + - " \"double_column\": { \"type\": \"double\" }," + - " \"integer_column\": { \"type\": \"integer\" }," + - " \"long_column\": { \"type\": \"long\" }," + - " \"keyword_column\": { \"type\": \"keyword\" }," + - " \"text_column\": { \"type\": \"text\" }," + - " \"binary_column\": { \"type\": \"binary\" }," + - " \"timestamp_column\": { \"type\": \"date\" }," + - " \"ipv4_column\": { \"type\": \"ip\" }," + - " \"ipv6_column\": { \"type\": \"ip\" }" + - " }" + - " }" + - " }" + - "}"; + String properties = """ + { + "properties": { + "field": { + "properties": { + "boolean_column": { "type": "boolean" }, + "float_column": { "type": "float" }, + "double_column": { "type": "double" }, + "integer_column": { "type": "integer" }, + "long_column": { "type": "long" }, + "keyword_column": { "type": "keyword" }, + "text_column": { "type": "text" }, + "binary_column": { "type": "binary" }, + "timestamp_column": { "type": "date" }, + "ipv4_column": { "type": "ip" }, + "ipv6_column": { "type": "ip" } + } + } + } + } + """; createIndex(indexName, properties); @@ -1627,20 +1660,22 @@ public void testDataTypesNested() .put("ipv6_column", "2001:db8:0:0:1:0:0:1") .buildOrThrow())); - MaterializedResult rows = computeActual("" + - "SELECT " + - "field.boolean_column, " + - "field.float_column, " + - "field.double_column, " + - "field.integer_column, " + - "field.long_column, " + - "field.keyword_column, " + - "field.text_column, " + - "field.binary_column, " + - "field.timestamp_column, " + - "field.ipv4_column, " + - "field.ipv6_column " + - "FROM types_nested"); + MaterializedResult rows = computeActual( + """ + SELECT + field.boolean_column, + field.float_column, + field.double_column, + field.integer_column, + field.long_column, + field.keyword_column, + field.text_column, + field.binary_column, + field.timestamp_column, + field.ipv4_column, + field.ipv6_column + FROM types_nested + """); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row(true, 1.0f, 1.0d, 1, 1L, "cool", "some text", new byte[] {(byte) 0xCA, (byte) 0xFE}, @@ -1657,27 +1692,28 @@ public void testNestedTypeDataTypesNested() String indexName = "nested_type_nested"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\":{" + - " \"nested_field\": {" + - " \"type\":\"nested\"," + - " \"properties\": {" + - " \"boolean_column\": { \"type\": \"boolean\" }," + - " \"float_column\": { \"type\": \"float\" }," + - " \"double_column\": { \"type\": \"double\" }," + - " \"integer_column\": { \"type\": \"integer\" }," + - " \"long_column\": { \"type\": \"long\" }," + - " \"keyword_column\": { \"type\": \"keyword\" }," + - " \"text_column\": { \"type\": \"text\" }," + - " \"binary_column\": { \"type\": \"binary\" }," + - " \"timestamp_column\": { \"type\": \"date\" }," + - " \"ipv4_column\": { \"type\": \"ip\" }," + - " \"ipv6_column\": { \"type\": \"ip\" }" + - " }" + - " }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "nested_field": { + "type":"nested", + "properties": { + "boolean_column": { "type": "boolean" }, + "float_column": { "type": "float" }, + "double_column": { "type": "double" }, + "integer_column": { "type": "integer" }, + "long_column": { "type": "long" }, + "keyword_column": { "type": "keyword" }, + "text_column": { "type": "text" }, + "binary_column": { "type": "binary" }, + "timestamp_column": { "type": "date" }, + "ipv4_column": { "type": "ip" }, + "ipv6_column": { "type": "ip" } + } + } + } + } + """; createIndex(indexName, mappings); @@ -1697,20 +1733,22 @@ public void testNestedTypeDataTypesNested() .put("ipv6_column", "2001:db8:0:0:1:0:0:1") .buildOrThrow())); - MaterializedResult rows = computeActual("" + - "SELECT " + - "nested_field.boolean_column, " + - "nested_field.float_column, " + - "nested_field.double_column, " + - "nested_field.integer_column, " + - "nested_field.long_column, " + - "nested_field.keyword_column, " + - "nested_field.text_column, " + - "nested_field.binary_column, " + - "nested_field.timestamp_column, " + - "nested_field.ipv4_column, " + - "nested_field.ipv6_column " + - "FROM nested_type_nested"); + MaterializedResult rows = computeActual( + """ + SELECT + nested_field.boolean_column, + nested_field.float_column, + nested_field.double_column, + nested_field.integer_column, + nested_field.long_column, + nested_field.keyword_column, + nested_field.text_column, + nested_field.binary_column, + nested_field.timestamp_column, + nested_field.ipv4_column, + nested_field.ipv6_column + FROM nested_type_nested + """); MaterializedResult expected = resultBuilder(getSession(), rows.getTypes()) .row(true, 1.0f, 1.0d, 1, 1L, "cool", "some text", new byte[] {(byte) 0xCA, (byte) 0xFE}, @@ -1751,12 +1789,13 @@ public void testNumericKeyword() { String indexName = "numeric_keyword"; @Language("JSON") - String properties = "" + - "{" + - " \"properties\":{" + - " \"numeric_keyword\": { \"type\": \"keyword\" }" + - " }" + - "}"; + String properties = """ + { + "properties":{ + "numeric_keyword": { "type": "keyword" } + } + } + """; createIndex(indexName, properties); index(indexName, ImmutableMap.of("numeric_keyword", 20)); @@ -1819,12 +1858,13 @@ public void testEmptyIndexWithMappings() String indexName = "test_empty_index_with_mappings"; @Language("JSON") - String mappings = "" + - "{" + - " \"properties\": { " + - " \"dummy_column\": { \"type\": \"long\" }" + - " }" + - "}"; + String mappings = """ + { + "properties": { + "dummy_column": { "type": "long" } + } + } + """; createIndex(indexName, mappings); @@ -1895,23 +1935,27 @@ public void testQueryTableFunction() // use aggregations @Language("JSON") - String query = "{\n" + - " \"size\": 0,\n" + - " \"aggs\" : {\n" + - " \"max_orderkey\" : { \"max\" : { \"field\" : \"orderkey\" } },\n" + - " \"sum_orderkey\" : { \"sum\" : { \"field\" : \"orderkey\" } }\n" + - " }\n" + - "}"; + String query = """ + { + "size": 0, + "aggs" : { + "max_orderkey" : { "max" : { "field" : "orderkey" } }, + "sum_orderkey" : { "sum" : { "field" : "orderkey" } } + } + } + """; assertQuery( - format("WITH data(r) AS (" + - " SELECT CAST(json_parse(result) AS ROW(aggregations ROW(max_orderkey ROW(value BIGINT), sum_orderkey ROW(value BIGINT)))) " + - " FROM TABLE(%s.system.raw_query(" + - " schema => 'tpch', " + - " index => 'orders', " + - " query => '%s'))) " + - "SELECT r.aggregations.max_orderkey.value, r.aggregations.sum_orderkey.value " + - "FROM data", catalogName, query), + """ + WITH data(r) AS ( + SELECT CAST(json_parse(result) AS ROW(aggregations ROW(max_orderkey ROW(value BIGINT), sum_orderkey ROW(value BIGINT)))) + FROM TABLE(%s.system.raw_query( + schema => 'tpch', + index => 'orders', + query => '%s'))) + SELECT r.aggregations.max_orderkey.value, r.aggregations.sum_orderkey.value + FROM data + """.formatted(catalogName, query), "VALUES (60000, 449872500)"); // no matches