You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "plusplusjiajia (via GitHub)" <gi...@apache.org> on 2026/01/09 09:54:32 UTC
[PR] [core]Add JSON serialization support for Predicate and Transform [paimon]
plusplusjiajia opened a new pull request, #6993:
URL: https://github.com/apache/paimon/pull/6993
### Purpose
Add Predicate and Transform json serialization utils
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2684680441
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Transform.java:
##########
@@ -21,10 +21,24 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
import java.io.Serializable;
import java.util.List;
/** Represents a transform function. */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Transform.Types.FIELD_TYPE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FieldTransform.class, name = Transform.Types.FIELD),
Review Comment:
Can we use `Transform.name` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2685206748
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Transform.java:
##########
@@ -21,11 +21,26 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
import java.io.Serializable;
import java.util.List;
/** Represents a transform function. */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Transform.FIELD_TRANSFORM)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FieldTransform.class, name = FieldTransform.NAME),
+ @JsonSubTypes.Type(value = CastTransform.class, name = CastTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatTransform.class, name = ConcatTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatWsTransform.class, name = ConcatWsTransform.NAME),
+ @JsonSubTypes.Type(value = UpperTransform.class, name = UpperTransform.NAME)
+})
public interface Transform extends Serializable {
+ String FIELD_TRANSFORM = "transform";
Review Comment:
"name" is better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2684680441
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Transform.java:
##########
@@ -21,10 +21,24 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
import java.io.Serializable;
import java.util.List;
/** Represents a transform function. */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Transform.Types.FIELD_TYPE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FieldTransform.class, name = Transform.Types.FIELD),
Review Comment:
Can we use `Transform.name` here? Maybe we can extract a static field for sub `Transform.name`, and ref it here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core]Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #6993:
URL: https://github.com/apache/paimon/pull/6993#issuecomment-3728925589
If possible, we'd better encapsulate the JSON serialization into specific classes, as this is the most effective way to avoid omissions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "plusplusjiajia (via GitHub)" <gi...@apache.org>.
plusplusjiajia commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2685292296
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Predicate.java:
##########
@@ -32,8 +35,16 @@
* @since 0.4.0
*/
@Public
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Predicate.FIELD_PREDICATE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = LeafPredicate.class, name = LeafPredicate.NAME),
+ @JsonSubTypes.Type(value = CompoundPredicate.class, name = CompoundPredicate.NAME)
+})
public interface Predicate extends Serializable {
-
+ String FIELD_PREDICATE = "predicate";
Review Comment:
> Let's modify it to `kind`?
done
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Transform.java:
##########
@@ -21,11 +21,26 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
import java.io.Serializable;
import java.util.List;
/** Represents a transform function. */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Transform.FIELD_TRANSFORM)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FieldTransform.class, name = FieldTransform.NAME),
+ @JsonSubTypes.Type(value = CastTransform.class, name = CastTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatTransform.class, name = ConcatTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatWsTransform.class, name = ConcatWsTransform.NAME),
+ @JsonSubTypes.Type(value = UpperTransform.class, name = UpperTransform.NAME)
+})
public interface Transform extends Serializable {
+ String FIELD_TRANSFORM = "transform";
Review Comment:
> "name" is better.
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2684883563
##########
paimon-common/src/test/java/org/apache/paimon/predicate/PredicateJsonSerdeTest.java:
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.paimon.predicate;
+
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.JsonSerdeUtil;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class PredicateJsonSerdeTest {
+
+ private static Stream<TestSpec> testData() {
+ PredicateBuilder builder = newBuilder();
+
+ return Stream.of(
+ // LeafPredicate - Equal
+ TestSpec.forPredicate(builder.equal(0, 1))
+ .expectJson(
+ "{\"type\":\"LEAF\",\"transform\":{\"type\":\"FIELD_REF\",\"fieldRef\":{\"index\":0,\"name\":\"f0\",\"type\":\"INT\"}},\"function\":{\"type\":\"EQUAL\"},\"literals\":[1]}"),
Review Comment:
Can we just let `function: EQUAL`? Just a string, not a struct.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "plusplusjiajia (via GitHub)" <gi...@apache.org>.
plusplusjiajia commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2681943769
##########
paimon-common/src/test/java/org/apache/paimon/predicate/PredicateJsonSerdeTest.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.paimon.predicate;
+
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.JsonSerdeUtil;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class PredicateJsonSerdeTest {
+
+ @Test
+ public void testLeafPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Predicate negatable = builder.equal(0, 1);
+ assertThat(negatable).isInstanceOf(LeafPredicate.class);
+ assertThat(negatable.negate()).isPresent();
+ assertThat(roundTrip(negatable)).isInstanceOf(LeafPredicate.class).isEqualTo(negatable);
+ assertThat(roundTrip(negatable).negate()).isEqualTo(negatable.negate());
+
+ Predicate nonNegatable = builder.like(2, BinaryString.fromString("%a%b%"));
+ assertThat(nonNegatable).isInstanceOf(LeafPredicate.class);
+ assertThat(nonNegatable.negate()).isEmpty();
+ Predicate restoredNonNegatable = roundTrip(nonNegatable);
+ assertThat(restoredNonNegatable).isInstanceOf(LeafPredicate.class);
+ assertThat(restoredNonNegatable.toString()).isEqualTo(nonNegatable.toString());
+ assertThat(restoredNonNegatable.negate()).isEmpty();
+ }
+
+ @Test
+ public void testTransformPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Transform cast =
+ new CastTransform(new FieldRef(0, "f0", new IntType()), DataTypes.BIGINT());
+ Transform upper =
+ new UpperTransform(
+ Collections.singletonList(new FieldRef(2, "f2", DataTypes.STRING())));
+ Transform concat =
+ new ConcatTransform(
+ Arrays.asList(
+ new FieldRef(1, "f1", DataTypes.STRING()),
+ BinaryString.fromString("-"),
+ new FieldRef(2, "f2", DataTypes.STRING()),
+ null));
+ Transform concatWs =
+ new ConcatWsTransform(
+ Arrays.asList(
+ BinaryString.fromString("|"),
+ new FieldRef(1, "f1", DataTypes.STRING()),
+ BinaryString.fromString("X"),
+ null,
+ new FieldRef(2, "f2", DataTypes.STRING())));
+
+ Predicate p1 = builder.greaterThan(cast, 10L);
+ Predicate p2 = builder.startsWith(upper, BinaryString.fromString("ABC"));
+ Predicate p3 = builder.contains(concat, BinaryString.fromString("m"));
+ Predicate p4 = builder.endsWith(concatWs, BinaryString.fromString("z"));
+ Predicate p5 = builder.in(upper, manyUpperStringsWithNulls());
+
+ for (Predicate p : Arrays.asList(p1, p2, p3, p4, p5)) {
+ assertThat(p)
+ .isInstanceOf(TransformPredicate.class)
+ .isNotInstanceOf(LeafPredicate.class);
+ assertThat(p.negate()).isEmpty();
+ Predicate restored = roundTrip(p);
+ assertThat(restored)
+ .isInstanceOf(TransformPredicate.class)
+ .isNotInstanceOf(LeafPredicate.class)
+ .isEqualTo(p);
+ assertThat(restored.negate()).isEmpty();
+ }
+ }
+
+ @Test
+ public void testCompoundPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Predicate like = builder.like(2, BinaryString.fromString("%a%b%"));
+ Predicate compound =
+ PredicateBuilder.and(
+ builder.equal(0, 1),
+ builder.in(3, manyInts()),
+ builder.in(3, Collections.emptyList()),
+ like,
+ PredicateBuilder.or(builder.equal(0, 7), builder.isNotNull(2)));
+
+ assertThat(compound).isInstanceOf(CompoundPredicate.class);
+
+ assertThat(compound.negate()).isEmpty();
+ Predicate restored = roundTrip(compound);
+ assertThat(restored).isInstanceOf(CompoundPredicate.class).isEqualTo(compound);
+ assertThat(restored.negate()).isEmpty();
+ }
+
+ private static PredicateBuilder newBuilder() {
+ return new PredicateBuilder(
+ RowType.of(new IntType(), DataTypes.STRING(), DataTypes.STRING(), new IntType()));
+ }
+
+ private static List<Object> manyInts() {
+ List<Object> ints = new ArrayList<>();
+ for (int i = 0; i < 21; i++) {
+ ints.add(i);
+ }
+ return ints;
+ }
+
+ private static List<Object> manyUpperStringsWithNulls() {
+ List<Object> strings = new ArrayList<>();
+ for (int i = 0; i < 21; i++) {
+ strings.add(i % 5 == 0 ? null : BinaryString.fromString("S" + i));
+ }
+ return strings;
+ }
+
+ private static Predicate roundTrip(Predicate predicate) {
+ String json = JsonSerdeUtil.toFlatJson(predicate);
+ return JsonSerdeUtil.fromJson(json, Predicate.class);
Review Comment:
> DataTypeJsonParserTest
Thansk for you review. It's really a useful suggestion, I've updated the test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #6993:
URL: https://github.com/apache/paimon/pull/6993#issuecomment-3738869300
I try to unify them in https://github.com/apache/paimon/pull/7015
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "plusplusjiajia (via GitHub)" <gi...@apache.org>.
plusplusjiajia commented on PR #6993:
URL: https://github.com/apache/paimon/pull/6993#issuecomment-3741625367
> Please rebase master.
good job!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #6993:
URL: https://github.com/apache/paimon/pull/6993#issuecomment-3741621030
Please rebase master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2681366085
##########
paimon-common/src/test/java/org/apache/paimon/predicate/PredicateJsonSerdeTest.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.paimon.predicate;
+
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.JsonSerdeUtil;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class PredicateJsonSerdeTest {
+
+ @Test
+ public void testLeafPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Predicate negatable = builder.equal(0, 1);
+ assertThat(negatable).isInstanceOf(LeafPredicate.class);
+ assertThat(negatable.negate()).isPresent();
+ assertThat(roundTrip(negatable)).isInstanceOf(LeafPredicate.class).isEqualTo(negatable);
+ assertThat(roundTrip(negatable).negate()).isEqualTo(negatable.negate());
+
+ Predicate nonNegatable = builder.like(2, BinaryString.fromString("%a%b%"));
+ assertThat(nonNegatable).isInstanceOf(LeafPredicate.class);
+ assertThat(nonNegatable.negate()).isEmpty();
+ Predicate restoredNonNegatable = roundTrip(nonNegatable);
+ assertThat(restoredNonNegatable).isInstanceOf(LeafPredicate.class);
+ assertThat(restoredNonNegatable.toString()).isEqualTo(nonNegatable.toString());
+ assertThat(restoredNonNegatable.negate()).isEmpty();
+ }
+
+ @Test
+ public void testTransformPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Transform cast =
+ new CastTransform(new FieldRef(0, "f0", new IntType()), DataTypes.BIGINT());
+ Transform upper =
+ new UpperTransform(
+ Collections.singletonList(new FieldRef(2, "f2", DataTypes.STRING())));
+ Transform concat =
+ new ConcatTransform(
+ Arrays.asList(
+ new FieldRef(1, "f1", DataTypes.STRING()),
+ BinaryString.fromString("-"),
+ new FieldRef(2, "f2", DataTypes.STRING()),
+ null));
+ Transform concatWs =
+ new ConcatWsTransform(
+ Arrays.asList(
+ BinaryString.fromString("|"),
+ new FieldRef(1, "f1", DataTypes.STRING()),
+ BinaryString.fromString("X"),
+ null,
+ new FieldRef(2, "f2", DataTypes.STRING())));
+
+ Predicate p1 = builder.greaterThan(cast, 10L);
+ Predicate p2 = builder.startsWith(upper, BinaryString.fromString("ABC"));
+ Predicate p3 = builder.contains(concat, BinaryString.fromString("m"));
+ Predicate p4 = builder.endsWith(concatWs, BinaryString.fromString("z"));
+ Predicate p5 = builder.in(upper, manyUpperStringsWithNulls());
+
+ for (Predicate p : Arrays.asList(p1, p2, p3, p4, p5)) {
+ assertThat(p)
+ .isInstanceOf(TransformPredicate.class)
+ .isNotInstanceOf(LeafPredicate.class);
+ assertThat(p.negate()).isEmpty();
+ Predicate restored = roundTrip(p);
+ assertThat(restored)
+ .isInstanceOf(TransformPredicate.class)
+ .isNotInstanceOf(LeafPredicate.class)
+ .isEqualTo(p);
+ assertThat(restored.negate()).isEmpty();
+ }
+ }
+
+ @Test
+ public void testCompoundPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Predicate like = builder.like(2, BinaryString.fromString("%a%b%"));
+ Predicate compound =
+ PredicateBuilder.and(
+ builder.equal(0, 1),
+ builder.in(3, manyInts()),
+ builder.in(3, Collections.emptyList()),
+ like,
+ PredicateBuilder.or(builder.equal(0, 7), builder.isNotNull(2)));
+
+ assertThat(compound).isInstanceOf(CompoundPredicate.class);
+
+ assertThat(compound.negate()).isEmpty();
+ Predicate restored = roundTrip(compound);
+ assertThat(restored).isInstanceOf(CompoundPredicate.class).isEqualTo(compound);
+ assertThat(restored.negate()).isEmpty();
+ }
+
+ private static PredicateBuilder newBuilder() {
+ return new PredicateBuilder(
+ RowType.of(new IntType(), DataTypes.STRING(), DataTypes.STRING(), new IntType()));
+ }
+
+ private static List<Object> manyInts() {
+ List<Object> ints = new ArrayList<>();
+ for (int i = 0; i < 21; i++) {
+ ints.add(i);
+ }
+ return ints;
+ }
+
+ private static List<Object> manyUpperStringsWithNulls() {
+ List<Object> strings = new ArrayList<>();
+ for (int i = 0; i < 21; i++) {
+ strings.add(i % 5 == 0 ? null : BinaryString.fromString("S" + i));
+ }
+ return strings;
+ }
+
+ private static Predicate roundTrip(Predicate predicate) {
+ String json = JsonSerdeUtil.toFlatJson(predicate);
+ return JsonSerdeUtil.fromJson(json, Predicate.class);
Review Comment:
Can we have JSON expected result in the tests? This is a standard. We need to solidify serialization-related issues in the test at least.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #6993:
URL: https://github.com/apache/paimon/pull/6993
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2684887478
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Transform.java:
##########
@@ -21,11 +21,26 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
import java.io.Serializable;
import java.util.List;
/** Represents a transform function. */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Transform.FIELD_TYPE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FieldTransform.class, name = FieldTransform.NAME),
+ @JsonSubTypes.Type(value = CastTransform.class, name = CastTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatTransform.class, name = ConcatTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatWsTransform.class, name = ConcatWsTransform.NAME),
+ @JsonSubTypes.Type(value = UpperTransform.class, name = UpperTransform.NAME)
+})
public interface Transform extends Serializable {
+ String FIELD_TYPE = "type";
Review Comment:
"transform"? "type" is confused to Data Type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2681371929
##########
paimon-common/src/test/java/org/apache/paimon/predicate/PredicateJsonSerdeTest.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.paimon.predicate;
+
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.IntType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.JsonSerdeUtil;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class PredicateJsonSerdeTest {
+
+ @Test
+ public void testLeafPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Predicate negatable = builder.equal(0, 1);
+ assertThat(negatable).isInstanceOf(LeafPredicate.class);
+ assertThat(negatable.negate()).isPresent();
+ assertThat(roundTrip(negatable)).isInstanceOf(LeafPredicate.class).isEqualTo(negatable);
+ assertThat(roundTrip(negatable).negate()).isEqualTo(negatable.negate());
+
+ Predicate nonNegatable = builder.like(2, BinaryString.fromString("%a%b%"));
+ assertThat(nonNegatable).isInstanceOf(LeafPredicate.class);
+ assertThat(nonNegatable.negate()).isEmpty();
+ Predicate restoredNonNegatable = roundTrip(nonNegatable);
+ assertThat(restoredNonNegatable).isInstanceOf(LeafPredicate.class);
+ assertThat(restoredNonNegatable.toString()).isEqualTo(nonNegatable.toString());
+ assertThat(restoredNonNegatable.negate()).isEmpty();
+ }
+
+ @Test
+ public void testTransformPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Transform cast =
+ new CastTransform(new FieldRef(0, "f0", new IntType()), DataTypes.BIGINT());
+ Transform upper =
+ new UpperTransform(
+ Collections.singletonList(new FieldRef(2, "f2", DataTypes.STRING())));
+ Transform concat =
+ new ConcatTransform(
+ Arrays.asList(
+ new FieldRef(1, "f1", DataTypes.STRING()),
+ BinaryString.fromString("-"),
+ new FieldRef(2, "f2", DataTypes.STRING()),
+ null));
+ Transform concatWs =
+ new ConcatWsTransform(
+ Arrays.asList(
+ BinaryString.fromString("|"),
+ new FieldRef(1, "f1", DataTypes.STRING()),
+ BinaryString.fromString("X"),
+ null,
+ new FieldRef(2, "f2", DataTypes.STRING())));
+
+ Predicate p1 = builder.greaterThan(cast, 10L);
+ Predicate p2 = builder.startsWith(upper, BinaryString.fromString("ABC"));
+ Predicate p3 = builder.contains(concat, BinaryString.fromString("m"));
+ Predicate p4 = builder.endsWith(concatWs, BinaryString.fromString("z"));
+ Predicate p5 = builder.in(upper, manyUpperStringsWithNulls());
+
+ for (Predicate p : Arrays.asList(p1, p2, p3, p4, p5)) {
+ assertThat(p)
+ .isInstanceOf(TransformPredicate.class)
+ .isNotInstanceOf(LeafPredicate.class);
+ assertThat(p.negate()).isEmpty();
+ Predicate restored = roundTrip(p);
+ assertThat(restored)
+ .isInstanceOf(TransformPredicate.class)
+ .isNotInstanceOf(LeafPredicate.class)
+ .isEqualTo(p);
+ assertThat(restored.negate()).isEmpty();
+ }
+ }
+
+ @Test
+ public void testCompoundPredicate() {
+ PredicateBuilder builder = newBuilder();
+
+ Predicate like = builder.like(2, BinaryString.fromString("%a%b%"));
+ Predicate compound =
+ PredicateBuilder.and(
+ builder.equal(0, 1),
+ builder.in(3, manyInts()),
+ builder.in(3, Collections.emptyList()),
+ like,
+ PredicateBuilder.or(builder.equal(0, 7), builder.isNotNull(2)));
+
+ assertThat(compound).isInstanceOf(CompoundPredicate.class);
+
+ assertThat(compound.negate()).isEmpty();
+ Predicate restored = roundTrip(compound);
+ assertThat(restored).isInstanceOf(CompoundPredicate.class).isEqualTo(compound);
+ assertThat(restored.negate()).isEmpty();
+ }
+
+ private static PredicateBuilder newBuilder() {
+ return new PredicateBuilder(
+ RowType.of(new IntType(), DataTypes.STRING(), DataTypes.STRING(), new IntType()));
+ }
+
+ private static List<Object> manyInts() {
+ List<Object> ints = new ArrayList<>();
+ for (int i = 0; i < 21; i++) {
+ ints.add(i);
+ }
+ return ints;
+ }
+
+ private static List<Object> manyUpperStringsWithNulls() {
+ List<Object> strings = new ArrayList<>();
+ for (int i = 0; i < 21; i++) {
+ strings.add(i % 5 == 0 ? null : BinaryString.fromString("S" + i));
+ }
+ return strings;
+ }
+
+ private static Predicate roundTrip(Predicate predicate) {
+ String json = JsonSerdeUtil.toFlatJson(predicate);
+ return JsonSerdeUtil.fromJson(json, Predicate.class);
Review Comment:
Something like `DataTypeJsonParserTest`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "plusplusjiajia (via GitHub)" <gi...@apache.org>.
plusplusjiajia commented on PR #6993:
URL: https://github.com/apache/paimon/pull/6993#issuecomment-3736935730
> e'd better encapsulate the JSON serialization into specific classes
Thanks for your advise! I've made the changes according to your advise. Please review it when you have a chance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core]Add JSON serialization support for Predicate and Transform [paimon]
Posted by "plusplusjiajia (via GitHub)" <gi...@apache.org>.
plusplusjiajia commented on PR #6993:
URL: https://github.com/apache/paimon/pull/6993#issuecomment-3729273158
> If possible, we'd better encapsulate the JSON serialization into specific classes, as this is the most effective way to avoid omissions.
Excellent suggestion!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2684887478
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Transform.java:
##########
@@ -21,11 +21,26 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataType;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonSubTypes;
+import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonTypeInfo;
+
import java.io.Serializable;
import java.util.List;
/** Represents a transform function. */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Transform.FIELD_TYPE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FieldTransform.class, name = FieldTransform.NAME),
+ @JsonSubTypes.Type(value = CastTransform.class, name = CastTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatTransform.class, name = ConcatTransform.NAME),
+ @JsonSubTypes.Type(value = ConcatWsTransform.class, name = ConcatWsTransform.NAME),
+ @JsonSubTypes.Type(value = UpperTransform.class, name = UpperTransform.NAME)
+})
public interface Transform extends Serializable {
+ String FIELD_TYPE = "type";
Review Comment:
"transform"?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2684889384
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Predicate.java:
##########
@@ -32,8 +35,16 @@
* @since 0.4.0
*/
@Public
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Predicate.FIELD_TYPE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = LeafPredicate.class, name = LeafPredicate.NAME),
+ @JsonSubTypes.Type(value = CompoundPredicate.class, name = CompoundPredicate.NAME)
+})
public interface Predicate extends Serializable {
-
+ String FIELD_TYPE = "type";
Review Comment:
"predicate"? "type" is confused to Data Type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Add JSON serialization support for Predicate and Transform [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #6993:
URL: https://github.com/apache/paimon/pull/6993#discussion_r2685216556
##########
paimon-common/src/main/java/org/apache/paimon/predicate/Predicate.java:
##########
@@ -32,8 +35,16 @@
* @since 0.4.0
*/
@Public
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = Predicate.FIELD_PREDICATE)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = LeafPredicate.class, name = LeafPredicate.NAME),
+ @JsonSubTypes.Type(value = CompoundPredicate.class, name = CompoundPredicate.NAME)
+})
public interface Predicate extends Serializable {
-
+ String FIELD_PREDICATE = "predicate";
Review Comment:
Let's modify it to `kind`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org