From 393c49182057c34cc3e65bc655003103cac6b871 Mon Sep 17 00:00:00 2001 From: amory Date: Wed, 6 Dec 2023 13:56:56 +0800 Subject: [PATCH] [FIX](map/struct)fix map/struct literal from fe (#28026) --- .../java/org/apache/doris/catalog/Type.java | 20 +++ .../apache/doris/analysis/ArrayLiteral.java | 12 +- .../apache/doris/analysis/LiteralExpr.java | 15 ++ .../org/apache/doris/analysis/MapLiteral.java | 26 ++- .../apache/doris/analysis/StructLiteral.java | 15 +- .../doris/analysis/ArrayLiteralTest.java | 26 ++- .../apache/doris/analysis/MapLiteralTest.java | 170 ++++++++++++++++++ .../doris/analysis/StructLiteralTest.java | 99 ++++++++++ 8 files changed, 368 insertions(+), 15 deletions(-) create mode 100644 fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java create mode 100644 fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java index 091c274f3e..b9dc9260dd 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java @@ -198,6 +198,8 @@ public abstract class Type { arraySubTypes.add(FLOAT); arraySubTypes.add(DOUBLE); arraySubTypes.add(DECIMALV2); + arraySubTypes.add(TIME); + arraySubTypes.add(TIMEV2); arraySubTypes.add(DATE); arraySubTypes.add(DATETIME); arraySubTypes.add(DATEV2); @@ -210,6 +212,11 @@ public abstract class Type { arraySubTypes.add(DECIMAL32); arraySubTypes.add(DECIMAL64); arraySubTypes.add(DECIMAL128); + arraySubTypes.add(DECIMAL256); + arraySubTypes.add(NULL); + arraySubTypes.add(ARRAY); + arraySubTypes.add(MAP); + arraySubTypes.add(STRUCT); mapSubTypes = Lists.newArrayList(); mapSubTypes.add(BOOLEAN); @@ -220,6 +227,9 @@ public abstract class Type { mapSubTypes.add(DECIMAL32); // same DEFAULT_DECIMALV3 mapSubTypes.add(DECIMAL64); mapSubTypes.add(DECIMAL128); + mapSubTypes.add(DECIMAL256); + mapSubTypes.add(TIME); + mapSubTypes.add(TIMEV2); mapSubTypes.add(DATE); mapSubTypes.add(DATETIME); mapSubTypes.add(DATEV2); @@ -230,6 +240,9 @@ public abstract class Type { mapSubTypes.add(VARCHAR); mapSubTypes.add(STRING); mapSubTypes.add(NULL); + mapSubTypes.add(ARRAY); + mapSubTypes.add(MAP); + mapSubTypes.add(STRUCT); structSubTypes = Lists.newArrayList(); structSubTypes.add(BOOLEAN); @@ -240,6 +253,9 @@ public abstract class Type { structSubTypes.add(DECIMAL32); // same DEFAULT_DECIMALV3 structSubTypes.add(DECIMAL64); structSubTypes.add(DECIMAL128); + structSubTypes.add(DECIMAL256); + structSubTypes.add(TIME); + structSubTypes.add(TIMEV2); structSubTypes.add(DATE); structSubTypes.add(DATETIME); structSubTypes.add(DATEV2); @@ -249,6 +265,10 @@ public abstract class Type { structSubTypes.add(CHAR); structSubTypes.add(VARCHAR); structSubTypes.add(STRING); + structSubTypes.add(NULL); + structSubTypes.add(ARRAY); + structSubTypes.add(MAP); + structSubTypes.add(STRUCT); } public static final Set DATE_SUPPORTED_JAVA_TYPE = Sets.newHashSet(LocalDate.class, java.util.Date.class, diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java index 7edba5d609..c9661a5527 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java @@ -18,7 +18,6 @@ package org.apache.doris.analysis; import org.apache.doris.catalog.ArrayType; -import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; import org.apache.doris.thrift.TExprNode; @@ -52,6 +51,9 @@ public class ArrayLiteral extends LiteralExpr { Type itemType = Type.NULL; boolean containsNull = true; for (LiteralExpr expr : exprs) { + if (!ArrayType.ARRAY.supportSubType(expr.getType())) { + throw new AnalysisException("Invalid item type in Array, not support " + expr.getType()); + } if (itemType == Type.NULL) { itemType = expr.getType(); } else { @@ -135,13 +137,7 @@ public class ArrayLiteral extends LiteralExpr { List list = new ArrayList<>(children.size()); children.forEach(v -> { // we should use type to decide we output array is suitable for json format - if (!(v instanceof NullLiteral) && v.getType().isScalarType() - && (Type.getNumericTypes().contains((ScalarType) v.getActualScalarType(v.getType())) - || v.getType() == Type.BOOLEAN)) { - list.add(v.getStringValueInFe()); - } else { - list.add(v.getStringValueForArray()); - } + list.add(getStringLiteralForComplexType(v)); }); return "[" + StringUtils.join(list, ", ") + "]"; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java index 28da8d2d20..c222070e28 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java @@ -109,6 +109,21 @@ public abstract class LiteralExpr extends Expr implements Comparable list = new ArrayList<>(children.size()); + for (int i = 0; i < children.size() && i + 1 < children.size(); i += 2) { + list.add(children.get(i).getStringValueForArray() + ":" + children.get(i + 1).getStringValueForArray()); + } + return "{" + StringUtils.join(list, ", ") + "}"; + } + + @Override + public String getStringValueInFe() { + List list = new ArrayList<>(children.size()); + for (int i = 0; i < children.size() && i + 1 < children.size(); i += 2) { + // we should use type to decide we output array is suitable for json format + if (children.get(i).getType().isComplexType()) { + // map key type do not support complex type + throw new UnsupportedOperationException("Unsupport key type for MAP: " + children.get(i).getType()); + } + list.add(children.get(i).getStringValueForArray() + + ":" + getStringLiteralForComplexType(children.get(i + 1))); + } + return "{" + StringUtils.join(list, ", ") + "}"; } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java index d4327fb979..4645bd9edc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java @@ -45,8 +45,8 @@ public class StructLiteral extends LiteralExpr { type = new StructType(); children = new ArrayList<>(); for (LiteralExpr expr : exprs) { - if (!expr.getType().isNull() && !type.supportSubType(expr.getType())) { - throw new AnalysisException("Invalid element type in STRUCT."); + if (!StructType.STRUCT.supportSubType(expr.getType())) { + throw new AnalysisException("Invalid element type in STRUCT: " + expr.getType()); } ((StructType) type).addField(new StructField(expr.getType())); children.add(expr); @@ -80,7 +80,16 @@ public class StructLiteral extends LiteralExpr { @Override public String getStringValueForArray() { - return null; + List list = new ArrayList<>(children.size()); + children.forEach(v -> list.add(v.getStringValueForArray())); + return "{" + StringUtils.join(list, ", ") + "}"; + } + + @Override + public String getStringValueInFe() { + List list = new ArrayList<>(children.size()); + children.forEach(v -> list.add(getStringLiteralForComplexType(v))); + return "{" + StringUtils.join(list, ", ") + "}"; } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java index fb9c6f0e18..009d15fdb9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java @@ -61,6 +61,16 @@ public class ArrayLiteralTest { ArrayLiteral arrayLiteral9 = new ArrayLiteral(); Assert.assertEquals("[]", arrayLiteral9.getStringValueForArray()); + + ArrayLiteral arrayLiteral = new ArrayLiteral(intLiteral1, floatLiteral); + MapLiteral mapLiteral = new MapLiteral(intLiteral1, floatLiteral); + StructLiteral structLiteral = new StructLiteral(intLiteral1, floatLiteral, dateLiteral); + ArrayLiteral arrayLiteral10 = new ArrayLiteral(arrayLiteral, arrayLiteral); + Assert.assertEquals("[[\"1\", \"2.15\"], [\"1\", \"2.15\"]]", arrayLiteral10.getStringValueForArray()); + ArrayLiteral arrayLiteral11 = new ArrayLiteral(mapLiteral); + Assert.assertEquals("[{\"1\":\"2.15\"}]", arrayLiteral11.getStringValueForArray()); + ArrayLiteral arrayLiteral12 = new ArrayLiteral(structLiteral); + Assert.assertEquals("[{\"1\", \"2.15\", \"2022-10-10\"}]", arrayLiteral12.getStringValueForArray()); } @@ -89,7 +99,8 @@ public class ArrayLiteralTest { Assert.assertEquals("[\"shortstring\", \"shortstring\"]", arrayLiteral3.getStringValueInFe()); ArrayLiteral arrayLiteral4 = new ArrayLiteral(largeIntLiteral, largeIntLiteral); - Assert.assertEquals("[1000000000000000000000, 1000000000000000000000]", arrayLiteral4.getStringValueInFe()); + Assert.assertEquals("[1000000000000000000000, 1000000000000000000000]", + arrayLiteral4.getStringValueInFe()); ArrayLiteral arrayLiteral5 = new ArrayLiteral(nullLiteral, nullLiteral); Assert.assertEquals("[null, null]", arrayLiteral5.getStringValueInFe()); @@ -98,7 +109,8 @@ public class ArrayLiteralTest { Assert.assertEquals("[\"2022-10-10\", \"2022-10-10\"]", arrayLiteral6.getStringValueInFe()); ArrayLiteral arrayLiteral7 = new ArrayLiteral(datetimeLiteral, datetimeLiteral); - Assert.assertEquals("[\"2022-10-10 12:10:10\", \"2022-10-10 12:10:10\"]", arrayLiteral7.getStringValueInFe()); + Assert.assertEquals("[\"2022-10-10 12:10:10\", \"2022-10-10 12:10:10\"]", + arrayLiteral7.getStringValueInFe()); ArrayLiteral arrayLiteral8 = new ArrayLiteral(arrayLiteral7, arrayLiteral7); Assert.assertEquals("[[\"2022-10-10 12:10:10\", \"2022-10-10 12:10:10\"], [\"2022-10-10 12:10:10\", \"2022-10-10 12:10:10\"]]", @@ -120,5 +132,15 @@ public class ArrayLiteralTest { ArrayLiteral arrayLiteral12 = new ArrayLiteral(nullLiteral, intLiteralWithNull); Assert.assertEquals("[null, 1]", arrayLiteral12.getStringValueInFe()); + ArrayLiteral arrayLiteral = new ArrayLiteral(intLiteral1, floatLiteral); + MapLiteral mapLiteral = new MapLiteral(intLiteral1, floatLiteral); + StructLiteral structLiteral = new StructLiteral(intLiteral1, floatLiteral, dateLiteral); + ArrayLiteral arrayLiteral13 = new ArrayLiteral(arrayLiteral, arrayLiteral); + Assert.assertEquals("[[\"1\", \"2.15\"], [\"1\", \"2.15\"]]", arrayLiteral13.getStringValueForArray()); + ArrayLiteral arrayLiteral14 = new ArrayLiteral(mapLiteral); + Assert.assertEquals("[{\"1\":\"2.15\"}]", arrayLiteral14.getStringValueForArray()); + ArrayLiteral arrayLiteral15 = new ArrayLiteral(structLiteral); + Assert.assertEquals("[{\"1\", \"2.15\", \"2022-10-10\"}]", arrayLiteral15.getStringValueForArray()); + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java new file mode 100644 index 0000000000..0ab4fbcbca --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java @@ -0,0 +1,170 @@ +// 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.doris.analysis; + +import org.apache.doris.catalog.Type; +import org.apache.doris.common.AnalysisException; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class MapLiteralTest { + static IntLiteral intLiteral1; + static FloatLiteral floatLiteral; + static FloatLiteral floatLiteral1; + static BoolLiteral boolLiteral; + static StringLiteral stringLiteral; + static LargeIntLiteral largeIntLiteral; + static NullLiteral nullLiteral; + static DateLiteral dateLiteral; + static DateLiteral datetimeLiteral; + static DecimalLiteral decimalLiteral1; + static DecimalLiteral decimalLiteral2; + static ArrayLiteral arrayLiteral; + static MapLiteral mapLiteral; + static StructLiteral structLiteral; + + + @BeforeAll + public static void setUp() throws AnalysisException { + intLiteral1 = new IntLiteral(1); + floatLiteral = new FloatLiteral("2.15"); + floatLiteral1 = new FloatLiteral((double) (11 * 3600 + 22 * 60 + 33), + FloatLiteral.getDefaultTimeType(Type.TIME)); + boolLiteral = new BoolLiteral(true); + stringLiteral = new StringLiteral("shortstring"); + largeIntLiteral = new LargeIntLiteral("1000000000000000000000"); + nullLiteral = new NullLiteral(); + dateLiteral = new DateLiteral("2022-10-10", Type.DATE); + datetimeLiteral = new DateLiteral("2022-10-10 12:10:10", Type.DATETIME); + decimalLiteral1 = new DecimalLiteral("1.0"); + decimalLiteral2 = new DecimalLiteral("2"); + arrayLiteral = new ArrayLiteral(intLiteral1, floatLiteral); + mapLiteral = new MapLiteral(intLiteral1, floatLiteral); + structLiteral = new StructLiteral(intLiteral1, floatLiteral, decimalLiteral1, dateLiteral); + + } + + @Test + public void testGetStringValueForArray() throws AnalysisException { + MapLiteral mapLiteral1 = new MapLiteral(intLiteral1, floatLiteral); + Assert.assertEquals("{\"1\":\"2.15\"}", mapLiteral1.getStringValueForArray()); + MapLiteral mapLiteral2 = new MapLiteral(boolLiteral, stringLiteral); + Assert.assertEquals("{\"1\":\"shortstring\"}", mapLiteral2.getStringValueForArray()); + MapLiteral mapLiteral3 = new MapLiteral(largeIntLiteral, dateLiteral); + Assert.assertEquals("{\"1000000000000000000000\":\"2022-10-10\"}", mapLiteral3.getStringValueForArray()); + MapLiteral mapLiteral4 = new MapLiteral(nullLiteral, nullLiteral); + Assert.assertEquals("{null:null}", mapLiteral4.getStringValueForArray()); + MapLiteral mapLiteral5 = new MapLiteral(datetimeLiteral, dateLiteral); + Assert.assertEquals("{\"2022-10-10 12:10:10\":\"2022-10-10\"}", mapLiteral5.getStringValueForArray()); + + MapLiteral mapLiteral6 = new MapLiteral(); + Assert.assertEquals("{}", mapLiteral6.getStringValueForArray()); + + MapLiteral mapLiteral7 = new MapLiteral(nullLiteral, intLiteral1); + Assert.assertEquals("{null:\"1\"}", mapLiteral7.getStringValueForArray()); + MapLiteral mapLiteral8 = new MapLiteral(intLiteral1, nullLiteral); + Assert.assertEquals("{\"1\":null}", mapLiteral8.getStringValueForArray()); + + MapLiteral mapLiteral10 = new MapLiteral(intLiteral1, arrayLiteral); + Assert.assertEquals("{\"1\":[\"1\", \"2.15\"]}", mapLiteral10.getStringValueForArray()); + try { + new MapLiteral(arrayLiteral, floatLiteral); + } catch (Exception e) { + Assert.assertEquals("errCode = 2, " + + "detailMessage = Invalid key type in Map, not support ARRAY", e.getMessage()); + } + + MapLiteral mapLiteral11 = new MapLiteral(decimalLiteral1, mapLiteral); + Assert.assertEquals("{\"1.0\":{\"1\":\"2.15\"}}", mapLiteral11.getStringValueForArray()); + try { + new MapLiteral(mapLiteral, decimalLiteral1); + } catch (Exception e) { + Assert.assertEquals("errCode = 2, " + + "detailMessage = Invalid key type in Map, not support MAP", e.getMessage()); + } + + MapLiteral mapLiteral13 = new MapLiteral(stringLiteral, structLiteral); + Assert.assertEquals("{\"shortstring\":{\"1\", \"2.15\", \"1.0\", \"2022-10-10\"}}", + mapLiteral13.getStringValueForArray()); + try { + new MapLiteral(structLiteral, stringLiteral); + } catch (Exception e) { + Assert.assertEquals("errCode = 2, detailMessage = Invalid key type in Map, " + + "not support STRUCT", e.getMessage()); + } + + } + + + @Test + public void testGetStringInFe() throws AnalysisException { + MapLiteral mapLiteral1 = new MapLiteral(intLiteral1, floatLiteral); + Assert.assertEquals("{\"1\":2.15}", mapLiteral1.getStringValueInFe()); + MapLiteral mapLiteral11 = new MapLiteral(intLiteral1, floatLiteral1); + Assert.assertEquals("{\"1\":\"11:22:33\"}", mapLiteral11.getStringValueInFe()); + MapLiteral mapLiteral2 = new MapLiteral(boolLiteral, stringLiteral); + Assert.assertEquals("{\"1\":\"shortstring\"}", mapLiteral2.getStringValueInFe()); + MapLiteral mapLiteral3 = new MapLiteral(largeIntLiteral, dateLiteral); + Assert.assertEquals("{\"1000000000000000000000\":\"2022-10-10\"}", mapLiteral3.getStringValueInFe()); + MapLiteral mapLiteral4 = new MapLiteral(floatLiteral1, nullLiteral); + Assert.assertEquals("{\"11:22:33\":null}", mapLiteral4.getStringValueInFe()); + MapLiteral mapLiteral5 = new MapLiteral(datetimeLiteral, dateLiteral); + Assert.assertEquals("{\"2022-10-10 12:10:10\":\"2022-10-10\"}", mapLiteral5.getStringValueInFe()); + MapLiteral mapLiteral6 = new MapLiteral(decimalLiteral1, decimalLiteral2); + Assert.assertEquals("{\"1.0\":2}", mapLiteral6.getStringValueInFe()); + + MapLiteral mapLiteral7 = new MapLiteral(); + Assert.assertEquals("{}", mapLiteral7.getStringValueInFe()); + MapLiteral mapLiteral8 = new MapLiteral(nullLiteral, intLiteral1); + Assert.assertEquals("{null:1}", mapLiteral8.getStringValueInFe()); + MapLiteral mapLiteral9 = new MapLiteral(intLiteral1, nullLiteral); + Assert.assertEquals("{\"1\":null}", mapLiteral9.getStringValueInFe()); + + MapLiteral mapLiteral10 = new MapLiteral(intLiteral1, arrayLiteral); + Assert.assertEquals("{\"1\":[\"1\", \"2.15\"]}", mapLiteral10.getStringValueForArray()); + try { + new MapLiteral(arrayLiteral, floatLiteral); + } catch (Exception e) { + Assert.assertEquals("errCode = 2, " + + "detailMessage = Invalid key type in Map, not support ARRAY", e.getMessage()); + } + + MapLiteral mapLiteral12 = new MapLiteral(decimalLiteral1, mapLiteral); + Assert.assertEquals("{\"1.0\":{\"1\":\"2.15\"}}", mapLiteral12.getStringValueForArray()); + try { + new MapLiteral(mapLiteral, decimalLiteral1); + } catch (Exception e) { + Assert.assertEquals("errCode = 2, " + + "detailMessage = Invalid key type in Map, not support MAP", e.getMessage()); + } + + MapLiteral mapLiteral13 = new MapLiteral(stringLiteral, structLiteral); + Assert.assertEquals("{\"shortstring\":{\"1\", \"2.15\", \"1.0\", \"2022-10-10\"}}", + mapLiteral13.getStringValueForArray()); + try { + new MapLiteral(structLiteral, stringLiteral); + } catch (Exception e) { + Assert.assertEquals("errCode = 2, " + + "detailMessage = Invalid key type in Map, " + + "not support STRUCT", e.getMessage()); + } + + } +} diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java new file mode 100644 index 0000000000..d844ef318f --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java @@ -0,0 +1,99 @@ +// 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.doris.analysis; + +import org.apache.doris.catalog.Type; +import org.apache.doris.common.AnalysisException; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class StructLiteralTest { + static IntLiteral intLiteral1; + static FloatLiteral floatLiteral; + static FloatLiteral floatLiteral1; + static BoolLiteral boolLiteral; + static StringLiteral stringLiteral; + static LargeIntLiteral largeIntLiteral; + static NullLiteral nullLiteral; + static DateLiteral dateLiteral; + static DateLiteral datetimeLiteral; + static DecimalLiteral decimalLiteral1; + static DecimalLiteral decimalLiteral2; + static ArrayLiteral arrayLiteral; + static MapLiteral mapLiteral; + static StructLiteral structLiteral; + + @BeforeAll + public static void setUp() throws AnalysisException { + intLiteral1 = new IntLiteral(1); + floatLiteral = new FloatLiteral("2.15"); + floatLiteral1 = new FloatLiteral((double) (11 * 3600 + 22 * 60 + 33), + FloatLiteral.getDefaultTimeType(Type.TIME)); + boolLiteral = new BoolLiteral(true); + stringLiteral = new StringLiteral("shortstring"); + largeIntLiteral = new LargeIntLiteral("1000000000000000000000"); + nullLiteral = new NullLiteral(); + dateLiteral = new DateLiteral("2022-10-10", Type.DATE); + datetimeLiteral = new DateLiteral("2022-10-10 12:10:10", Type.DATETIME); + decimalLiteral1 = new DecimalLiteral("1.0"); + decimalLiteral2 = new DecimalLiteral("2"); + arrayLiteral = new ArrayLiteral(intLiteral1, floatLiteral); + mapLiteral = new MapLiteral(intLiteral1, floatLiteral); + structLiteral = new StructLiteral(intLiteral1, floatLiteral, decimalLiteral1, dateLiteral); + + } + + @Test + public void testGetStringValueForArray() throws AnalysisException { + StructLiteral structLiteral1 = new StructLiteral(intLiteral1, floatLiteral, floatLiteral1, boolLiteral, + stringLiteral, largeIntLiteral, decimalLiteral1, decimalLiteral2, dateLiteral, + datetimeLiteral); + Assert.assertEquals("{\"1\", \"2.15\", \"11:22:33\", \"1\", \"shortstring\", " + + "\"1000000000000000000000\", \"1.0\", \"2\", \"2022-10-10\", \"2022-10-10 12:10:10\"}", + structLiteral1.getStringValueForArray()); + StructLiteral structLiteral2 = new StructLiteral(arrayLiteral, mapLiteral, structLiteral); + Assert.assertEquals("{[\"1\", \"2.15\"], {\"1\":\"2.15\"}, {\"1\", \"2.15\", \"1.0\", \"2022-10-10\"}}", + structLiteral2.getStringValueForArray()); + StructLiteral structLiteral3 = new StructLiteral(); + Assert.assertEquals("{}", structLiteral3.getStringValueForArray()); + + StructLiteral nullStruct = new StructLiteral(nullLiteral, intLiteral1); + Assert.assertEquals("{null, \"1\"}", nullStruct.getStringValueForArray()); + + } + + + @Test + public void testGetStringInFe() throws AnalysisException { + StructLiteral structLiteral1 = new StructLiteral(intLiteral1, floatLiteral, floatLiteral1, boolLiteral, + stringLiteral, largeIntLiteral, decimalLiteral1, decimalLiteral2, dateLiteral, datetimeLiteral); + Assert.assertEquals("{1, 2.15, \"11:22:33\", 1, \"shortstring\", 1000000000000000000000, 1.0, 2, " + + "\"2022-10-10\", \"2022-10-10 12:10:10\"}", + structLiteral1.getStringValueInFe()); + StructLiteral structLiteral2 = new StructLiteral(arrayLiteral, mapLiteral, structLiteral); + Assert.assertEquals("{[1.0, 2.15], {\"1\":2.15}, {1, 2.15, 1.0, \"2022-10-10\"}}", + structLiteral2.getStringValueInFe()); + StructLiteral structLiteral3 = new StructLiteral(); + Assert.assertEquals("{}", structLiteral3.getStringValueInFe()); + + StructLiteral nullStruct = new StructLiteral(nullLiteral, intLiteral1); + Assert.assertEquals("{null, 1}", nullStruct.getStringValueInFe()); + } +}