This is an automated email from the ASF dual-hosted git repository.

alexpl pushed a commit to branch sql-calcite
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/sql-calcite by this push:
     new 5c7314c  IGNITE-14545 Unicode support - Fixes #9030.
5c7314c is described below

commit 5c7314c36a4abf4e5fe8c7cd3aa9c2d96a663076
Author: Aleksey Plekhanov <[email protected]>
AuthorDate: Mon May 17 15:57:20 2021 +0300

    IGNITE-14545 Unicode support - Fixes #9030.
    
    Signed-off-by: Aleksey Plekhanov <[email protected]>
---
 .../query/calcite/type/IgniteTypeFactory.java      |  7 ++
 .../processors/query/calcite/DataTypesTest.java    | 94 ++++++++++++++++++++++
 .../ignite/testsuites/IgniteCalciteTestSuite.java  |  2 +
 .../sql/aggregate/aggregates/test_aggr_string.test |  6 ++
 .../aggregates/test_aggr_string.test_ignore        | 24 +++++-
 .../sql/types/string/test_unicode.test_ignored     |  2 +-
 6 files changed, 132 insertions(+), 3 deletions(-)

diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
index b62b3fd..7f7c8cb 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.ignite.internal.processors.query.calcite.type;
 
 import java.lang.reflect.Type;
 import java.math.BigDecimal;
+import java.nio.charset.Charset;
 import java.sql.Timestamp;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -215,6 +216,12 @@ public class IgniteTypeFactory extends JavaTypeFactoryImpl 
{
         return super.leastRestrictive(types);
     }
 
+    /** {@inheritDoc} */
+    @Override public Charset getDefaultCharset() {
+        // Use JVM default charset rather then Calcite default charset 
(ISO-8859-1).
+        return Charset.defaultCharset();
+    }
+
     /** */
     private boolean allEquals(List<RelDataType> types) {
         assert types.size() > 1;
diff --git 
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/DataTypesTest.java
 
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/DataTypesTest.java
new file mode 100644
index 0000000..dbeb589
--- /dev/null
+++ 
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/DataTypesTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import com.google.common.collect.ImmutableSet;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.QueryEngine;
+import org.apache.ignite.internal.processors.query.calcite.util.Commons;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Test SQL data types.
+ */
+public class DataTypesTest extends GridCommonAbstractTest {
+    /** */
+    private static QueryEngine qryEngine;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        IgniteEx grid = startGrid();
+
+        qryEngine = Commons.lookupComponent(grid.context(), QueryEngine.class);
+    }
+
+    /** */
+    @Test
+    public void testUnicodeStrings() {
+        grid().getOrCreateCache(new CacheConfiguration<Integer, String>()
+            .setName("string_cache")
+            .setSqlSchema("PUBLIC")
+            .setQueryEntities(F.asList(new QueryEntity(Integer.class, 
String.class).setTableName("string_table")))
+        );
+
+        String[] values = new String[] {"Кирилл", "Müller", "我是谁", "ASCII"};
+
+        int key = 0;
+
+        // Insert as inlined values.
+        for (String val : values)
+            executeSql("INSERT INTO string_table (_key, _val) VALUES (" + 
key++ + ", '" + val + "')");
+
+        List<List<?>> rows = executeSql("SELECT _val FROM string_table");
+
+        assertEquals(ImmutableSet.copyOf(values), rows.stream().map(r -> 
r.get(0)).collect(Collectors.toSet()));
+
+        executeSql("DELETE FROM string_table");
+
+        // Insert as parameters.
+        for (String val : values)
+            executeSql("INSERT INTO string_table (_key, _val) VALUES (?, ?)", 
key++, val);
+
+        rows = executeSql("SELECT _val FROM string_table");
+
+        assertEquals(ImmutableSet.copyOf(values), rows.stream().map(r -> 
r.get(0)).collect(Collectors.toSet()));
+
+        rows = executeSql("SELECT substring(_val, 1, 2) FROM string_table");
+
+        assertEquals(ImmutableSet.of("Ки", "Mü", "我是", "AS"),
+            rows.stream().map(r -> r.get(0)).collect(Collectors.toSet()));
+
+        for (String val : values) {
+            rows = executeSql("SELECT char_length(_val) FROM string_table 
WHERE _val = ?", val);
+
+            assertEquals(1, rows.size());
+            assertEquals(val.length(), rows.get(0).get(0));
+        }
+    }
+
+    /** */
+    public List<List<?>> executeSql(String sql, Object... params) {
+        return qryEngine.query(null, "PUBLIC", sql, params).get(0).getAll();
+    }
+}
diff --git 
a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
 
b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
index 4414be0..93b2d3e 100644
--- 
a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
+++ 
b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
@@ -22,6 +22,7 @@ import 
org.apache.ignite.internal.processors.query.calcite.CalciteBasicSecondary
 import 
org.apache.ignite.internal.processors.query.calcite.CalciteErrorHandlilngIntegrationTest;
 import 
org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessorTest;
 import org.apache.ignite.internal.processors.query.calcite.CancelTest;
+import org.apache.ignite.internal.processors.query.calcite.DataTypesTest;
 import org.apache.ignite.internal.processors.query.calcite.DateTimeTest;
 import org.apache.ignite.internal.processors.query.calcite.FunctionsTest;
 import org.apache.ignite.internal.processors.query.calcite.LimitOffsetTest;
@@ -57,6 +58,7 @@ import org.junit.runners.Suite;
     CancelTest.class,
     QueryCheckerTest.class,
     DateTimeTest.class,
+    DataTypesTest.class,
     LimitOffsetTest.class,
     SqlFieldsQueryUsageTest.class,
     AggregatesIntegrationTest.class,
diff --git 
a/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test 
b/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test
index cfc4961..3ac9f62 100644
--- a/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test
+++ b/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test
@@ -2,6 +2,12 @@
 # description: Test aggregations on strings
 # group: [aggregates]
 
+query TTTTI
+SELECT NULL as a, NULL as b, NULL as c, NULL as d, 1 as id UNION SELECT 
'Кирилл' as a, 'Müller' as b, '我是谁' as c, 'ASCII' as d, 2 as id ORDER BY 1 
NULLS FIRST
+----
+NULL   NULL    NULL    NULL    1
+Кирилл Müller  我是谁     ASCII   2
+
 statement ok
 CREATE TABLE test (a INTEGER, s VARCHAR);
 
diff --git 
a/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test_ignore
 
b/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test_ignore
index 33b849c..e59608f 100644
--- 
a/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test_ignore
+++ 
b/modules/calcite/src/test/sql/aggregate/aggregates/test_aggr_string.test_ignore
@@ -2,10 +2,9 @@
 # description: Test aggregations on strings
 # group: [aggregates]
 # Ignore: https://issues.apache.org/jira/browse/IGNITE-14544
-# Ignore: https://issues.apache.org/jira/browse/IGNITE-14545
 
 query TTTTI
-SELECT NULL as a, NULL as b, NULL as c, NULL as d, 1 as id UNION SELECT 
'Кирилл' as a, 'Müller' as b, '我是谁' as c, 'ASCII' as d, 2 as id ORDER BY 1
+SELECT NULL as a, NULL as b, NULL as c, NULL as d, 1 as id UNION SELECT 
'Кирилл' as a, 'Müller' as b, '我是谁' as c, 'ASCII' as d, 2 as id ORDER BY 1 
NULLS FIRST
 ----
 NULL   NULL    NULL    NULL    1
 Кирилл Müller  我是谁     ASCII   2
@@ -60,3 +59,24 @@ SELECT a, COUNT(*), COUNT(s), COUNT(DISTINCT s) FROM test 
WHERE s IS NOT NULL GR
 ----
 11     2       2       1
 12     2       2       1
+
+# string min/max with long strings
+statement ok
+CREATE TABLE test_strings(s VARCHAR);
+INSERT INTO test_strings VALUES ('aaaaaaaahello'), 
('bbbbbbbbbbbbbbbbbbbbhello'), ('ccccccccccccccchello'), 
('aaaaaaaaaaaaaaaaaaaaaaaahello')
+
+query II
+SELECT MIN(s), MAX(s) FROM test_strings;
+----
+aaaaaaaaaaaaaaaaaaaaaaaahello  ccccccccccccccchello
+
+# string min/max with long strings 2
+statement ok
+CREATE TABLE test_strings2(s VARCHAR);
+INSERT INTO test_strings2 VALUES ('a'), ('aa'), ('A'), ('AA'), ('D')
+
+query II
+SELECT MAX(s), MIN(s) FROM test_strings2;
+----
+aa     A
+
diff --git 
a/modules/calcite/src/test/sql/types/string/test_unicode.test_ignored 
b/modules/calcite/src/test/sql/types/string/test_unicode.test_ignored
index 790b3b5..2090cff 100644
--- a/modules/calcite/src/test/sql/types/string/test_unicode.test_ignored
+++ b/modules/calcite/src/test/sql/types/string/test_unicode.test_ignored
@@ -1,7 +1,7 @@
 # name: test/sql/types/string/test_unicode.test
 # description: Test unicode strings
 # group: [string]
-# Ignore: https://issues.apache.org/jira/browse/IGNITE-14545
+# Ignore: https://issues.apache.org/jira/browse/IGNITE-14677
 
 # insert unicode strings into the database
 statement ok

Reply via email to