|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.doris.nereids.trees.plans.commands.info; |
| 19 | + |
| 20 | +import org.apache.doris.analysis.AddPartitionFieldClause; |
| 21 | +import org.apache.doris.alter.AlterOpType; |
| 22 | + |
| 23 | +import org.junit.jupiter.api.Assertions; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import java.util.Map; |
| 27 | + |
| 28 | +public class AddPartitionFieldOpTest { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testIdentityTransform() { |
| 32 | + AddPartitionFieldOp op = new AddPartitionFieldOp(null, null, "category"); |
| 33 | + Assertions.assertEquals(AlterOpType.SCHEMA_CHANGE, op.getOpType()); |
| 34 | + Assertions.assertNull(op.getTransformName()); |
| 35 | + Assertions.assertNull(op.getTransformArg()); |
| 36 | + Assertions.assertEquals("category", op.getColumnName()); |
| 37 | + Assertions.assertEquals("ADD PARTITION FIELD category", op.toSql()); |
| 38 | + |
| 39 | + AddPartitionFieldClause clause = (AddPartitionFieldClause) op.translateToLegacyAlterClause(); |
| 40 | + Assertions.assertNotNull(clause); |
| 41 | + Assertions.assertNull(clause.getTransformName()); |
| 42 | + Assertions.assertNull(clause.getTransformArg()); |
| 43 | + Assertions.assertEquals("category", clause.getColumnName()); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testTimeTransform() { |
| 48 | + AddPartitionFieldOp op = new AddPartitionFieldOp("year", null, "ts"); |
| 49 | + Assertions.assertEquals("year", op.getTransformName()); |
| 50 | + Assertions.assertNull(op.getTransformArg()); |
| 51 | + Assertions.assertEquals("ts", op.getColumnName()); |
| 52 | + Assertions.assertEquals("ADD PARTITION FIELD year(ts)", op.toSql()); |
| 53 | + |
| 54 | + AddPartitionFieldClause clause = (AddPartitionFieldClause) op.translateToLegacyAlterClause(); |
| 55 | + Assertions.assertEquals("year", clause.getTransformName()); |
| 56 | + Assertions.assertNull(clause.getTransformArg()); |
| 57 | + Assertions.assertEquals("ts", clause.getColumnName()); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testBucketTransform() { |
| 62 | + AddPartitionFieldOp op = new AddPartitionFieldOp("bucket", 16, "id"); |
| 63 | + Assertions.assertEquals("bucket", op.getTransformName()); |
| 64 | + Assertions.assertEquals(16, op.getTransformArg()); |
| 65 | + Assertions.assertEquals("id", op.getColumnName()); |
| 66 | + Assertions.assertEquals("ADD PARTITION FIELD bucket(16, id)", op.toSql()); |
| 67 | + |
| 68 | + AddPartitionFieldClause clause = (AddPartitionFieldClause) op.translateToLegacyAlterClause(); |
| 69 | + Assertions.assertEquals("bucket", clause.getTransformName()); |
| 70 | + Assertions.assertEquals(16, clause.getTransformArg()); |
| 71 | + Assertions.assertEquals("id", clause.getColumnName()); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void testTruncateTransform() { |
| 76 | + AddPartitionFieldOp op = new AddPartitionFieldOp("truncate", 10, "name"); |
| 77 | + Assertions.assertEquals("truncate", op.getTransformName()); |
| 78 | + Assertions.assertEquals(10, op.getTransformArg()); |
| 79 | + Assertions.assertEquals("name", op.getColumnName()); |
| 80 | + Assertions.assertEquals("ADD PARTITION FIELD truncate(10, name)", op.toSql()); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testMonthTransform() { |
| 85 | + AddPartitionFieldOp op = new AddPartitionFieldOp("month", null, "created_date"); |
| 86 | + Assertions.assertEquals("ADD PARTITION FIELD month(created_date)", op.toSql()); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testDayTransform() { |
| 91 | + AddPartitionFieldOp op = new AddPartitionFieldOp("day", null, "ts"); |
| 92 | + Assertions.assertEquals("ADD PARTITION FIELD day(ts)", op.toSql()); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testHourTransform() { |
| 97 | + AddPartitionFieldOp op = new AddPartitionFieldOp("hour", null, "ts"); |
| 98 | + Assertions.assertEquals("ADD PARTITION FIELD hour(ts)", op.toSql()); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testProperties() { |
| 103 | + AddPartitionFieldOp op = new AddPartitionFieldOp("bucket", 32, "id"); |
| 104 | + Map<String, String> properties = op.getProperties(); |
| 105 | + Assertions.assertNotNull(properties); |
| 106 | + Assertions.assertTrue(properties.isEmpty()); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testAllowOpMTMV() { |
| 111 | + AddPartitionFieldOp op = new AddPartitionFieldOp("bucket", 16, "id"); |
| 112 | + Assertions.assertFalse(op.allowOpMTMV()); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void testNeedChangeMTMVState() { |
| 117 | + AddPartitionFieldOp op = new AddPartitionFieldOp("bucket", 16, "id"); |
| 118 | + Assertions.assertFalse(op.needChangeMTMVState()); |
| 119 | + } |
| 120 | +} |
| 121 | + |
0 commit comments