Skip to content

Commit

Permalink
[fix](case) fix struct format out files (apache#37350)
Browse files Browse the repository at this point in the history
follow up apache#37349
1. Some of constants are calculated in FE, it should output same format
as in BE.
    Add `FormatOptions` to control the output format of complex types.

3. Modify some of result files of test cases.
  • Loading branch information
morningman committed Jul 8, 2024
1 parent a6ec78e commit a0fdf62
Show file tree
Hide file tree
Showing 48 changed files with 1,102 additions and 709 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.ArrayType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;

Expand Down Expand Up @@ -133,21 +134,21 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
public String getStringValueForArray(FormatOptions options) {
List<String> list = new ArrayList<>(children.size());
children.forEach(v -> list.add(v.getStringValueForArray()));
children.forEach(v -> list.add(v.getStringValueForArray(options)));
return "[" + StringUtils.join(list, ", ") + "]";
}

@Override
public String getStringValueInFe() {
public String getStringValueInFe(FormatOptions options) {
List<String> list = new ArrayList<>(children.size());
children.forEach(v -> {
String stringLiteral;
if (v instanceof NullLiteral) {
stringLiteral = "null";
stringLiteral = options.getNullFormat();
} else {
stringLiteral = getStringLiteralForComplexType(v);
stringLiteral = getStringLiteralForComplexType(v, options);
}
// we should use type to decide we output array is suitable for json format
list.add(stringLiteral);
Expand All @@ -156,14 +157,14 @@ public String getStringValueInFe() {
}

@Override
public String getStringValueForStreamLoad() {
public String getStringValueForStreamLoad(FormatOptions options) {
List<String> list = new ArrayList<>(children.size());
children.forEach(v -> {
String stringLiteral;
if (v instanceof NullLiteral) {
stringLiteral = "null";
} else {
stringLiteral = getStringLiteralForStreamLoad(v);
stringLiteral = getStringLiteralForStreamLoad(v, options);
}
// we should use type to decide we output array is suitable for json format
list.add(stringLiteral);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.thrift.TBoolLiteral;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
Expand Down Expand Up @@ -106,8 +107,8 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.TypeUtils;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.Pair;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TExpr;
Expand Down Expand Up @@ -580,8 +581,8 @@ public boolean isNullable() {
}

@Override
public String getStringValueForArray() {
return children.get(0).getStringValueForArray();
public String getStringValueForArray(FormatOptions options) {
return children.get(0).getStringValueForArray(options);
}

public void setNotFold(boolean notFold) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.InvalidFormatException;
import org.apache.doris.nereids.util.DateUtils;
import org.apache.doris.qe.SessionVariable;
Expand Down Expand Up @@ -727,8 +728,8 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}

public void roundCeiling(int newScale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.NotImplementedException;
import org.apache.doris.common.io.Text;
import org.apache.doris.qe.SessionVariable;
Expand Down Expand Up @@ -258,7 +259,7 @@ public int compareLiteral(LiteralExpr expr) {
}

@Override
public String getStringValueInFe() {
public String getStringValueInFe(FormatOptions options) {
return value.toPlainString();
}

Expand All @@ -273,8 +274,8 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.TreeNode;
import org.apache.doris.common.io.Writable;
import org.apache.doris.nereids.util.Utils;
Expand Down Expand Up @@ -2200,11 +2201,11 @@ public String getStringValue() {
return "";
}

public String getStringValueInFe() {
public String getStringValueInFe(FormatOptions options) {
return getStringValue();
}

public String getStringValueForStreamLoad() {
public String getStringValueForStreamLoad(FormatOptions options) {
return getStringValue();
}

Expand All @@ -2213,7 +2214,7 @@ public String getStringValueForStreamLoad() {
// ["1", "2", "3"]
// ["a", "b", "c"]
// [["1", "2", "3"], ["1"], ["3"]]
public String getStringValueForArray() {
public String getStringValueForArray(FormatOptions options) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.NotImplementedException;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
Expand Down Expand Up @@ -146,7 +147,7 @@ public String getStringValue() {
}

@Override
public String getStringValueInFe() {
public String getStringValueInFe(FormatOptions options) {
if (type == Type.TIME || type == Type.TIMEV2) {
// FloatLiteral used to represent TIME type, here we need to remove apostrophe from timeStr
// for example '11:22:33' -> 11:22:33
Expand All @@ -158,13 +159,13 @@ public String getStringValueInFe() {
}

@Override
public String getStringValueForArray() {
public String getStringValueForArray(FormatOptions options) {
String ret = getStringValue();
if (type == Type.TIME || type == Type.TIMEV2) {
// here already wrapped in ''
ret = ret.substring(1, ret.length() - 1);
}
return "\"" + ret + "\"";
return options.getNestedStringWrapper() + ret + options.getNestedStringWrapper();
}

public static Type getDefaultTimeType(Type type) throws AnalysisException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TIPv4Literal;
Expand Down Expand Up @@ -136,7 +137,7 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TIPv6Literal;
Expand Down Expand Up @@ -101,7 +102,7 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.NotImplementedException;
import org.apache.doris.common.util.ByteBufferUtil;
import org.apache.doris.qe.ConnectContext;
Expand Down Expand Up @@ -284,8 +285,8 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.io.Text;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
Expand Down Expand Up @@ -99,7 +100,7 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
public String getStringValueForArray(FormatOptions options) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.io.Text;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
Expand Down Expand Up @@ -192,8 +193,8 @@ public String getStringValue() {
}

@Override
public String getStringValueForArray() {
return "\"" + getStringValue() + "\"";
public String getStringValueForArray(FormatOptions options) {
return options.getNestedStringWrapper() + getStringValue() + options.getNestedStringWrapper();
}

@Override
Expand Down
22 changes: 11 additions & 11 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.common.NotImplementedException;
import org.apache.doris.mysql.MysqlProto;
import org.apache.doris.thrift.TExprNode;
Expand Down Expand Up @@ -114,30 +115,29 @@ public static LiteralExpr create(String value, Type type) throws AnalysisExcepti
return literalExpr;
}


public static String getStringLiteralForComplexType(Expr v) {
public static String getStringLiteralForComplexType(Expr v, FormatOptions options) {
if (!(v instanceof NullLiteral) && v.getType().isScalarType()
&& (Type.getNumericTypes().contains((ScalarType) v.getActualScalarType(v.getType()))
|| v.getType() == Type.BOOLEAN)) {
return v.getStringValueInFe();
return v.getStringValueInFe(options);
} else if (v.getType().isComplexType()) {
// these type should also call getStringValueInFe which should handle special case for itself
return v.getStringValueInFe();
return v.getStringValueInFe(options);
} else {
return v.getStringValueForArray();
return v.getStringValueForArray(options);
}
}

public static String getStringLiteralForStreamLoad(Expr v) {
public static String getStringLiteralForStreamLoad(Expr v, FormatOptions options) {
if (!(v instanceof NullLiteral) && v.getType().isScalarType()
&& (Type.getNumericTypes().contains((ScalarType) v.getActualScalarType(v.getType()))
|| v.getType() == Type.BOOLEAN)) {
return v.getStringValueInFe();
return v.getStringValueInFe(options);
} else if (v.getType().isComplexType()) {
// these type should also call getStringValueInFe which should handle special case for itself
return v.getStringValueForStreamLoad();
return v.getStringValueForStreamLoad(options);
} else {
return v.getStringValueForArray();
return v.getStringValueForArray(options);
}
}

Expand Down Expand Up @@ -266,12 +266,12 @@ public int compareTo(LiteralExpr literalExpr) {
@Override
public abstract String getStringValue();

public String getStringValueInFe() {
public String getStringValueInFe(FormatOptions options) {
return getStringValue();
}

@Override
public abstract String getStringValueForArray();
public abstract String getStringValueForArray(FormatOptions options);

public long getLongValue() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.MapType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
Expand Down Expand Up @@ -171,25 +172,27 @@ private String getStringValue(Expr expr) {
}

@Override
public String getStringValueForArray() {
public String getStringValueForArray(FormatOptions options) {
List<String> 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());
list.add(children.get(i).getStringValueForArray(options)
+ options.getMapKeyDelim()
+ children.get(i + 1).getStringValueForArray(options));
}
return "{" + StringUtils.join(list, ", ") + "}";
}

@Override
public String getStringValueInFe() {
public String getStringValueInFe(FormatOptions options) {
List<String> 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());
throw new UnsupportedOperationException("Unsupported key type for MAP: " + children.get(i).getType());
}
list.add(getStringLiteralForComplexType(children.get(i))
+ ":" + getStringLiteralForComplexType(children.get(i + 1)));
list.add(getStringLiteralForComplexType(children.get(i), options)
+ options.getMapKeyDelim() + getStringLiteralForComplexType(children.get(i + 1), options));
}
return "{" + StringUtils.join(list, ", ") + "}";
}
Expand Down
Loading

0 comments on commit a0fdf62

Please sign in to comment.