yangzhg commented on a change in pull request #6054:
URL: https://github.com/apache/incubator-doris/pull/6054#discussion_r656703036
##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java
##########
@@ -167,11 +175,113 @@ public void analyze(Analyzer analyzer) throws
AnalysisException {
public void analyze(Analyzer analyzer, SelectStmt stmt) throws
AnalysisException {
analyze(analyzer);
- List<SelectListItem> items = stmt.getSelectList().getItems();
- for (SelectListItem item:items) {
- if (item.getExpr().getType() == Type.LARGEINT &&
isParquetFormat()) {
- throw new AnalysisException("currently parquet do not support
largeint type");
+
+ if (isParquetFormat()) {
+ analyzeForParquetFormat(stmt.getResultExprs());
+ }
+ }
+
+ private void analyzeForParquetFormat(List<Expr> resultExprs) throws
AnalysisException {
+ if (this.schema.isEmpty()) {
+ genParquetSchema(resultExprs);
+ }
+
+ // check schema number
+ if (resultExprs.size() != this.schema.size()) {
+ throw new AnalysisException("Parquet schema number does not equal
to select item number");
+ }
+
+ // check type
+ for (int i = 0; i < this.schema.size(); ++i) {
+ String type = this.schema.get(i).get(1);
+ Type resultType = resultExprs.get(i).getType();
+ switch (resultType.getPrimitiveType()) {
+ case BOOLEAN:
+ if (!type.equals("boolean")) {
+ throw new AnalysisException("project field type is
BOOLEAN, should use boolean, but the type of column "
+ + i + " is " + type);
+ }
+ break;
+ case TINYINT:
+ case SMALLINT:
+ case INT:
+ if (!type.equals("int32")) {
+ throw new AnalysisException("project field type is
TINYINT/SMALLINT/INT, should use int32, "
+ + "but the definition type of column " + i + "
is " + type);
+ }
+ break;
+ case BIGINT:
+ case DATE:
+ case DATETIME:
+ if (!type.equals("int64")) {
+ throw new AnalysisException("project field type is
BIGINT/DATE/DATETIME, should use int64, " +
+ "but the definition type of column " + i + "
is " + type);
+ }
+ break;
+ case FLOAT:
+ if (!type.equals("float")) {
+ throw new AnalysisException("project field type is
FLOAT, should use float, but the definition type of column "
+ + i + " is " + type);
+ }
+ break;
+ case DOUBLE:
+ if (!type.equals("double")) {
+ throw new AnalysisException("project field type is
DOUBLE, should use double, but the definition type of column "
+ + i + " is " + type);
+ }
+ break;
+ case CHAR:
+ case VARCHAR:
+ case DECIMAL:
+ case DECIMALV2:
+ if (!type.equals("byte_array")) {
+ throw new AnalysisException("project field type is
CHAR/VARCHAR/DECIMAL, should use byte_array, " +
+ "but the definition type of column " + i + "
is " + type);
+ }
+ break;
+ default:
+ throw new AnalysisException("Parquet format does not
support column type: " + resultType.getPrimitiveType());
+ }
+ }
+ }
+
+ private void genParquetSchema(List<Expr> resultExprs) throws
AnalysisException {
+ Preconditions.checkState(this.schema.isEmpty());
+ for (int i = 0; i < resultExprs.size(); ++i) {
+ Expr expr = resultExprs.get(i);
+ List<String> column = new ArrayList<>();
+ column.add("required");
+ switch (expr.getType().getPrimitiveType()) {
+ case BOOLEAN:
+ column.add("boolean");
+ break;
+ case TINYINT:
+ case SMALLINT:
+ case INT:
+ column.add("int32");
+ break;
+ case BIGINT:
+ case DATE:
+ case DATETIME:
+ column.add("int64");
+ break;
+ case FLOAT:
+ column.add("float");
+ break;
+ case DOUBLE:
+ column.add("double");
+ break;
+ case CHAR:
+ case VARCHAR:
+ case DECIMAL:
Review comment:
remove DECIMAL
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]