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

lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-presto.git


The following commit(s) were added to refs/heads/main by this push:
     new 68bf40e  [fix] fix CharType filter (#11)
68bf40e is described below

commit 68bf40edb99ec1cd0f06381ffdcf325986887018
Author: YeJunHao <[email protected]>
AuthorDate: Sun Jun 25 16:35:23 2023 +0800

    [fix] fix CharType filter (#11)
---
 .../paimon/presto/PrestoFilterConverter.java       |  6 +++--
 .../paimon/presto/PrestoFilterConverterTest.java   | 29 ++++++++++++++++++++++
 .../paimon/prestosql/PrestoSqlFilterConverter.java |  3 ++-
 .../prestosql/TestPrestoSqlFilterConverter.java    | 26 +++++++++++++++++++
 4 files changed, 61 insertions(+), 3 deletions(-)

diff --git 
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoFilterConverter.java
 
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoFilterConverter.java
index b1bba71..ef66525 100644
--- 
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoFilterConverter.java
+++ 
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoFilterConverter.java
@@ -18,6 +18,7 @@
 
 package org.apache.paimon.presto;
 
+import org.apache.paimon.data.BinaryString;
 import org.apache.paimon.predicate.Predicate;
 import org.apache.paimon.predicate.PredicateBuilder;
 import org.apache.paimon.types.RowType;
@@ -28,6 +29,7 @@ import com.facebook.presto.common.predicate.TupleDomain;
 import com.facebook.presto.common.type.ArrayType;
 import com.facebook.presto.common.type.BigintType;
 import com.facebook.presto.common.type.BooleanType;
+import com.facebook.presto.common.type.CharType;
 import com.facebook.presto.common.type.DateType;
 import com.facebook.presto.common.type.DecimalType;
 import com.facebook.presto.common.type.Decimals;
@@ -210,8 +212,8 @@ public class PrestoFilterConverter {
             return TimeUnit.MILLISECONDS.toMicros((Long) prestoNativeValue);
         }
 
-        if (type instanceof VarcharType) {
-            return ((Slice) prestoNativeValue).toStringUtf8();
+        if (type instanceof VarcharType || type instanceof CharType) {
+            return BinaryString.fromBytes(((Slice) 
prestoNativeValue).getBytes());
         }
 
         if (type instanceof VarbinaryType) {
diff --git 
a/paimon-presto-common/src/test/java/org/apache/paimon/presto/PrestoFilterConverterTest.java
 
b/paimon-presto-common/src/test/java/org/apache/paimon/presto/PrestoFilterConverterTest.java
index fb5a654..5121c92 100644
--- 
a/paimon-presto-common/src/test/java/org/apache/paimon/presto/PrestoFilterConverterTest.java
+++ 
b/paimon-presto-common/src/test/java/org/apache/paimon/presto/PrestoFilterConverterTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.paimon.presto;
 
+import org.apache.paimon.data.BinaryString;
 import org.apache.paimon.predicate.Predicate;
 import org.apache.paimon.predicate.PredicateBuilder;
 import org.apache.paimon.types.DataField;
@@ -28,7 +29,9 @@ import com.facebook.presto.common.predicate.Domain;
 import com.facebook.presto.common.predicate.Range;
 import com.facebook.presto.common.predicate.TupleDomain;
 import com.facebook.presto.common.predicate.ValueSet;
+import com.facebook.presto.common.type.CharType;
 import com.google.common.collect.ImmutableMap;
+import io.airlift.slice.Slices;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
@@ -120,4 +123,30 @@ public class PrestoFilterConverterTest {
         Predicate actualIn = converter.convert(in).get();
         assertThat(actualIn).isEqualTo(expectedIn);
     }
+
+    @Test
+    public void testCharType() {
+        RowType rowType =
+                new RowType(
+                        Collections.singletonList(
+                                new DataField(
+                                        0, "date", new 
org.apache.paimon.types.CharType(10))));
+        PrestoFilterConverter converter = new PrestoFilterConverter(rowType);
+        PredicateBuilder builder = new PredicateBuilder(rowType);
+        PrestoColumnHandle dateColumn =
+                PrestoColumnHandle.create(
+                        "date",
+                        new org.apache.paimon.types.CharType(10),
+                        createTestFunctionAndTypeManager());
+        TupleDomain<PrestoColumnHandle> eq =
+                TupleDomain.withColumnDomains(
+                        ImmutableMap.of(
+                                dateColumn,
+                                Domain.singleValue(
+                                        CharType.createCharType(10),
+                                        Slices.utf8Slice("2020-11-11"))));
+        Predicate expectedEqq = builder.equal(0, 
BinaryString.fromString("2020-11-11"));
+        Predicate actualEqq = converter.convert(eq).get();
+        assertThat(actualEqq).isEqualTo(expectedEqq);
+    }
 }
diff --git 
a/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlFilterConverter.java
 
b/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlFilterConverter.java
index 2e1c794..947f2b2 100644
--- 
a/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlFilterConverter.java
+++ 
b/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlFilterConverter.java
@@ -33,6 +33,7 @@ import io.prestosql.spi.predicate.TupleDomain;
 import io.prestosql.spi.type.ArrayType;
 import io.prestosql.spi.type.BigintType;
 import io.prestosql.spi.type.BooleanType;
+import io.prestosql.spi.type.CharType;
 import io.prestosql.spi.type.DateType;
 import io.prestosql.spi.type.DecimalType;
 import io.prestosql.spi.type.DoubleType;
@@ -229,7 +230,7 @@ public class PrestoSqlFilterConverter {
             return Timestamp.fromEpochMillis(unpackMillisUtc((Long) 
prestosqlNativeValue));
         }
 
-        if (type instanceof VarcharType) {
+        if (type instanceof VarcharType || type instanceof CharType) {
             return BinaryString.fromBytes(((Slice) 
prestosqlNativeValue).getBytes());
         }
 
diff --git 
a/paimon-prestosql-common/src/test/java/org/apache/paimon/prestosql/TestPrestoSqlFilterConverter.java
 
b/paimon-prestosql-common/src/test/java/org/apache/paimon/prestosql/TestPrestoSqlFilterConverter.java
index c12a4e3..887f30b 100644
--- 
a/paimon-prestosql-common/src/test/java/org/apache/paimon/prestosql/TestPrestoSqlFilterConverter.java
+++ 
b/paimon-prestosql-common/src/test/java/org/apache/paimon/prestosql/TestPrestoSqlFilterConverter.java
@@ -18,6 +18,7 @@
 
 package org.apache.paimon.prestosql;
 
+import org.apache.paimon.data.BinaryString;
 import org.apache.paimon.predicate.Predicate;
 import org.apache.paimon.predicate.PredicateBuilder;
 import org.apache.paimon.types.DataField;
@@ -25,10 +26,12 @@ import org.apache.paimon.types.IntType;
 import org.apache.paimon.types.RowType;
 
 import com.google.common.collect.ImmutableMap;
+import io.airlift.slice.Slices;
 import io.prestosql.spi.predicate.Domain;
 import io.prestosql.spi.predicate.Range;
 import io.prestosql.spi.predicate.TupleDomain;
 import io.prestosql.spi.predicate.ValueSet;
+import io.prestosql.spi.type.CharType;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
@@ -118,4 +121,27 @@ public class TestPrestoSqlFilterConverter {
         Predicate actualIn = converter.convert(in).get();
         assertThat(actualIn).isEqualTo(expectedIn);
     }
+
+    @Test
+    public void testCharType() {
+        RowType rowType =
+                new RowType(
+                        Collections.singletonList(
+                                new DataField(
+                                        0, "date", new 
org.apache.paimon.types.CharType(10))));
+        PrestoSqlFilterConverter converter = new 
PrestoSqlFilterConverter(rowType);
+        PredicateBuilder builder = new PredicateBuilder(rowType);
+        PrestoSqlColumnHandle dateColumn =
+                PrestoSqlColumnHandle.of("date", new 
org.apache.paimon.types.CharType(10), null);
+        TupleDomain<PrestoSqlColumnHandle> eq =
+                TupleDomain.withColumnDomains(
+                        ImmutableMap.of(
+                                dateColumn,
+                                Domain.singleValue(
+                                        CharType.createCharType(10),
+                                        Slices.utf8Slice("2020-11-11"))));
+        Predicate expectedEqq = builder.equal(0, 
BinaryString.fromString("2020-11-11"));
+        Predicate actualEqq = converter.convert(eq).get();
+        assertThat(actualEqq).isEqualTo(expectedEqq);
+    }
 }

Reply via email to