Skip to content

Commit

Permalink
[apache#4913] fix(API): fix call bucketTransform arguments failed (ap…
Browse files Browse the repository at this point in the history
…ache#5268)

### What changes were proposed in this pull request?

fix call bucketTransform arguments failed

### Why are the changes needed?

Fix: apache#4913 

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

tests added
  • Loading branch information
mchades authored and mplmoknijb committed Nov 6, 2024
1 parent 39f8d00 commit 779e33d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions api/src/test/java/org/apache/gravitino/rel/TestTransforms.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer>) arguments[0]).value());
Assertions.assertEquals(fieldName, ((NamedReference.FieldReference) arguments[1]).fieldName());
}

@Test
public void testSingleFieldTransform() {
Column column = Column.of("col_1", Types.ByteType.get());
Expand Down

0 comments on commit 779e33d

Please sign in to comment.