|
18 | 18 | package org.apache.doris.nereids.trees.expressions.functions; |
19 | 19 |
|
20 | 20 | import org.apache.doris.catalog.FunctionSignature; |
21 | | -import org.apache.doris.nereids.exceptions.AnalysisException; |
22 | 21 | import org.apache.doris.nereids.trees.expressions.Expression; |
23 | 22 | import org.apache.doris.nereids.trees.expressions.literal.ArrayLiteral; |
24 | 23 | import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; |
25 | 24 | import org.apache.doris.nereids.trees.expressions.literal.DateLiteral; |
26 | 25 | import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral; |
27 | 26 | import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal; |
28 | 27 | import org.apache.doris.nereids.trees.expressions.literal.DecimalV3Literal; |
29 | | -import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral; |
30 | 28 | import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; |
31 | 29 | import org.apache.doris.nereids.trees.expressions.literal.Literal; |
32 | 30 | import org.apache.doris.nereids.trees.expressions.literal.MapLiteral; |
33 | 31 | import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; |
34 | 32 | import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral; |
35 | 33 | import org.apache.doris.nereids.trees.expressions.literal.TimeV2Literal; |
36 | | -import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; |
37 | 34 | import org.apache.doris.nereids.types.ArrayType; |
38 | 35 | import org.apache.doris.nereids.types.BigIntType; |
39 | 36 | import org.apache.doris.nereids.types.BooleanType; |
40 | | -import org.apache.doris.nereids.types.DataType; |
41 | 37 | import org.apache.doris.nereids.types.DateTimeType; |
42 | 38 | import org.apache.doris.nereids.types.DateTimeV2Type; |
43 | 39 | import org.apache.doris.nereids.types.DateType; |
|
50 | 46 | import org.apache.doris.nereids.types.NullType; |
51 | 47 | import org.apache.doris.nereids.types.SmallIntType; |
52 | 48 | import org.apache.doris.nereids.types.TimeV2Type; |
53 | | -import org.apache.doris.nereids.types.VariantType; |
54 | 49 | import org.apache.doris.nereids.types.coercion.AnyDataType; |
55 | 50 | import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; |
56 | 51 | import org.apache.doris.nereids.types.coercion.FollowToArgumentType; |
@@ -537,199 +532,6 @@ void testComplexNestedMixedTimePrecisionPromotion() { |
537 | 532 | ((ArrayType) ((MapType) signature.returnType).getValueType()).getItemType()); |
538 | 533 | } |
539 | 534 |
|
540 | | - @Test |
541 | | - void testNoDynamicComputeVariantArgs() { |
542 | | - FunctionSignature signature = FunctionSignature.ret(DoubleType.INSTANCE).args(IntegerType.INSTANCE); |
543 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, Collections.emptyList()); |
544 | | - Assertions.assertTrue(signature.returnType instanceof DoubleType); |
545 | | - } |
546 | | - |
547 | | - @Test |
548 | | - void testDynamicComputeVariantArgsSingleVariant() { |
549 | | - VariantType variantType = new VariantType(100); |
550 | | - FunctionSignature signature = FunctionSignature.ret(VariantType.INSTANCE) |
551 | | - .args(VariantType.INSTANCE, IntegerType.INSTANCE); |
552 | | - |
553 | | - List<Expression> arguments = Lists.newArrayList( |
554 | | - new MockVariantExpression(variantType), |
555 | | - new IntegerLiteral(42)); |
556 | | - |
557 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
558 | | - |
559 | | - Assertions.assertTrue(signature.returnType instanceof VariantType); |
560 | | - Assertions.assertEquals(100, ((VariantType) signature.returnType).getVariantMaxSubcolumnsCount()); |
561 | | - Assertions.assertEquals(10000, ((VariantType) signature.returnType).getVariantMaxSparseColumnStatisticsSize()); |
562 | | - |
563 | | - Assertions.assertTrue(signature.getArgType(0) instanceof VariantType); |
564 | | - Assertions.assertEquals(100, ((VariantType) signature.getArgType(0)).getVariantMaxSubcolumnsCount()); |
565 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(0)).getVariantMaxSparseColumnStatisticsSize()); |
566 | | - |
567 | | - Assertions.assertTrue(signature.getArgType(1) instanceof IntegerType); |
568 | | - } |
569 | | - |
570 | | - @Test |
571 | | - void testDynamicComputeVariantArgsMultipleVariants() { |
572 | | - VariantType variantType1 = new VariantType(150); |
573 | | - VariantType variantType2 = new VariantType(250); |
574 | | - FunctionSignature signature = FunctionSignature.ret(IntegerType.INSTANCE) |
575 | | - .args(VariantType.INSTANCE, VariantType.INSTANCE); |
576 | | - |
577 | | - List<Expression> arguments = Lists.newArrayList( |
578 | | - new MockVariantExpression(variantType1), |
579 | | - new MockVariantExpression(variantType2)); |
580 | | - |
581 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
582 | | - |
583 | | - Assertions.assertTrue(signature.getArgType(0) instanceof VariantType); |
584 | | - Assertions.assertEquals(150, ((VariantType) signature.getArgType(0)).getVariantMaxSubcolumnsCount()); |
585 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(0)).getVariantMaxSparseColumnStatisticsSize()); |
586 | | - Assertions.assertTrue(signature.getArgType(1) instanceof VariantType); |
587 | | - Assertions.assertEquals(250, ((VariantType) signature.getArgType(1)).getVariantMaxSubcolumnsCount()); |
588 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(1)).getVariantMaxSparseColumnStatisticsSize()); |
589 | | - Assertions.assertTrue(signature.returnType instanceof IntegerType); |
590 | | - } |
591 | | - |
592 | | - @Test |
593 | | - void testDynamicComputeVariantArgsMixedTypesWithSingleVariant() { |
594 | | - VariantType variantType = new VariantType(75); |
595 | | - FunctionSignature signature = FunctionSignature.ret(BooleanType.INSTANCE) |
596 | | - .args(VariantType.INSTANCE, IntegerType.INSTANCE, DoubleType.INSTANCE); |
597 | | - |
598 | | - List<Expression> arguments = Lists.newArrayList( |
599 | | - new MockVariantExpression(variantType), |
600 | | - new IntegerLiteral(10), |
601 | | - new DoubleLiteral(3.14)); |
602 | | - |
603 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
604 | | - |
605 | | - Assertions.assertTrue(signature.getArgType(0) instanceof VariantType); |
606 | | - Assertions.assertEquals(75, ((VariantType) signature.getArgType(0)).getVariantMaxSubcolumnsCount()); |
607 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(0)).getVariantMaxSparseColumnStatisticsSize()); |
608 | | - Assertions.assertTrue(signature.getArgType(1) instanceof IntegerType); |
609 | | - Assertions.assertTrue(signature.getArgType(2) instanceof DoubleType); |
610 | | - |
611 | | - Assertions.assertTrue(signature.returnType instanceof BooleanType); |
612 | | - } |
613 | | - |
614 | | - @Test |
615 | | - void testDynamicComputeVariantArgsWithNullLiteral() { |
616 | | - FunctionSignature signature = FunctionSignature.ret(BooleanType.INSTANCE) |
617 | | - .args(VariantType.INSTANCE, IntegerType.INSTANCE); |
618 | | - |
619 | | - List<Expression> arguments = Lists.newArrayList( |
620 | | - new NullLiteral(), |
621 | | - new IntegerLiteral(10)); |
622 | | - |
623 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
624 | | - |
625 | | - Assertions.assertTrue(signature.getArgType(0) instanceof VariantType); |
626 | | - Assertions.assertEquals(0, ((VariantType) signature.getArgType(0)).getVariantMaxSubcolumnsCount()); |
627 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(0)).getVariantMaxSparseColumnStatisticsSize()); |
628 | | - Assertions.assertTrue(signature.getArgType(1) instanceof IntegerType); |
629 | | - } |
630 | | - |
631 | | - @Test |
632 | | - void testDynamicComputeVariantArgsNoVariantReturnType() { |
633 | | - VariantType variantType = new VariantType(300); |
634 | | - FunctionSignature signature = FunctionSignature.ret(IntegerType.INSTANCE) |
635 | | - .args(VariantType.INSTANCE); |
636 | | - |
637 | | - List<Expression> arguments = Lists.newArrayList( |
638 | | - new MockVariantExpression(variantType)); |
639 | | - |
640 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
641 | | - |
642 | | - Assertions.assertTrue(signature.returnType instanceof IntegerType); |
643 | | - |
644 | | - Assertions.assertTrue(signature.getArgType(0) instanceof VariantType); |
645 | | - Assertions.assertEquals(300, ((VariantType) signature.getArgType(0)).getVariantMaxSubcolumnsCount()); |
646 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(0)).getVariantMaxSparseColumnStatisticsSize()); |
647 | | - } |
648 | | - |
649 | | - @Test |
650 | | - void testDynamicComputeVariantArgsWithVarArgsThrowsException() { |
651 | | - VariantType variantType1 = new VariantType(150); |
652 | | - VariantType variantType2 = new VariantType(250); |
653 | | - FunctionSignature signature = FunctionSignature.ret(VariantType.INSTANCE) |
654 | | - .args(VariantType.INSTANCE, VariantType.INSTANCE); |
655 | | - |
656 | | - List<Expression> arguments = Lists.newArrayList( |
657 | | - new MockVariantExpression(variantType1), |
658 | | - new MockVariantExpression(variantType2)); |
659 | | - |
660 | | - AnalysisException exception = Assertions.assertThrows(AnalysisException.class, () -> { |
661 | | - ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
662 | | - }); |
663 | | - |
664 | | - Assertions.assertEquals("variant type is not supported in multiple arguments", exception.getMessage()); |
665 | | - } |
666 | | - |
667 | | - @Test |
668 | | - void testDynamicComputeVariantArgsWithComputeSignature() { |
669 | | - VariantType variantType = new VariantType(200); |
670 | | - FunctionSignature signature = FunctionSignature.ret(VariantType.INSTANCE) |
671 | | - .args(VariantType.INSTANCE); |
672 | | - |
673 | | - List<Expression> arguments = Lists.newArrayList( |
674 | | - new MockVariantExpression(variantType)); |
675 | | - |
676 | | - signature = ComputeSignatureHelper.dynamicComputeVariantArgs(signature, arguments); |
677 | | - |
678 | | - Assertions.assertTrue(signature.returnType instanceof VariantType); |
679 | | - Assertions.assertEquals(200, ((VariantType) signature.returnType).getVariantMaxSubcolumnsCount()); |
680 | | - Assertions.assertEquals(10000, ((VariantType) signature.returnType).getVariantMaxSparseColumnStatisticsSize()); |
681 | | - Assertions.assertTrue(signature.getArgType(0) instanceof VariantType); |
682 | | - Assertions.assertEquals(200, ((VariantType) signature.getArgType(0)).getVariantMaxSubcolumnsCount()); |
683 | | - Assertions.assertEquals(10000, ((VariantType) signature.getArgType(0)).getVariantMaxSparseColumnStatisticsSize()); |
684 | | - } |
685 | | - |
686 | | - /** |
687 | | - * Mock Expression class for testing VariantType |
688 | | - */ |
689 | | - private static class MockVariantExpression extends Expression { |
690 | | - private final VariantType variantType; |
691 | | - |
692 | | - public MockVariantExpression(VariantType variantType) { |
693 | | - super(Collections.emptyList()); |
694 | | - this.variantType = variantType; |
695 | | - } |
696 | | - |
697 | | - @Override |
698 | | - public DataType getDataType() { |
699 | | - return variantType; |
700 | | - } |
701 | | - |
702 | | - @Override |
703 | | - public boolean nullable() { |
704 | | - return true; |
705 | | - } |
706 | | - |
707 | | - @Override |
708 | | - public Expression withChildren(List<Expression> children) { |
709 | | - return this; |
710 | | - } |
711 | | - |
712 | | - @Override |
713 | | - public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { |
714 | | - return visitor.visit(this, context); |
715 | | - } |
716 | | - |
717 | | - @Override |
718 | | - public int arity() { |
719 | | - return 0; |
720 | | - } |
721 | | - |
722 | | - @Override |
723 | | - public Expression child(int index) { |
724 | | - throw new IndexOutOfBoundsException("MockVariantExpression has no children"); |
725 | | - } |
726 | | - |
727 | | - @Override |
728 | | - public List<Expression> children() { |
729 | | - return Collections.emptyList(); |
730 | | - } |
731 | | - } |
732 | | - |
733 | 535 | @Test |
734 | 536 | void testDateV1AndDateTimeV1TypeConversion() { |
735 | 537 | // Test DateType -> DateV2Type conversion with implementAnyDataTypeWithOutIndex |
|
0 commit comments