From 779e33dc70d5ffc51b378376fce6baa72d45cc89 Mon Sep 17 00:00:00 2001 From: mchades Date: Fri, 25 Oct 2024 17:15:05 +0800 Subject: [PATCH] [#4913] fix(API): fix call bucketTransform arguments failed (#5268) ### What changes were proposed in this pull request? fix call bucketTransform arguments failed ### Why are the changes needed? Fix: #4913 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? tests added --- .../rel/expressions/transforms/Transforms.java | 2 +- .../org/apache/gravitino/rel/TestTransforms.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/apache/gravitino/rel/expressions/transforms/Transforms.java b/api/src/main/java/org/apache/gravitino/rel/expressions/transforms/Transforms.java index 73cb33b553b..035b3305955 100644 --- a/api/src/main/java/org/apache/gravitino/rel/expressions/transforms/Transforms.java +++ b/api/src/main/java/org/apache/gravitino/rel/expressions/transforms/Transforms.java @@ -447,7 +447,7 @@ public String name() { /** @return The arguments to the transform. */ @Override public Expression[] arguments() { - return ObjectArrays.concat(numBuckets, fields); + return ObjectArrays.concat(new Expression[] {numBuckets}, fields, Expression.class); } @Override diff --git a/api/src/test/java/org/apache/gravitino/rel/TestTransforms.java b/api/src/test/java/org/apache/gravitino/rel/TestTransforms.java index 615e2e39004..6404ac555a6 100644 --- a/api/src/test/java/org/apache/gravitino/rel/TestTransforms.java +++ b/api/src/test/java/org/apache/gravitino/rel/TestTransforms.java @@ -35,11 +35,25 @@ import org.apache.gravitino.rel.expressions.NamedReference; import org.apache.gravitino.rel.expressions.literals.Literals; import org.apache.gravitino.rel.expressions.transforms.Transform; +import org.apache.gravitino.rel.expressions.transforms.Transforms; import org.apache.gravitino.rel.types.Types; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class TestTransforms { + @Test + public void testBucketTransform() { + Column column = Column.of("col_1", Types.ByteType.get()); + String[] fieldName = new String[] {column.name()}; + + Transform bucket = Transforms.bucket(10, fieldName); + Expression[] arguments = bucket.arguments(); + Assertions.assertEquals(2, arguments.length); + Assertions.assertInstanceOf(Literals.LiteralImpl.class, arguments[0]); + Assertions.assertEquals(10, ((Literals.LiteralImpl) arguments[0]).value()); + Assertions.assertEquals(fieldName, ((NamedReference.FieldReference) arguments[1]).fieldName()); + } + @Test public void testSingleFieldTransform() { Column column = Column.of("col_1", Types.ByteType.get());