This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ca6f34c87 [fix](view) Fix view not showing specific lengths for 
varchar type (#12107)
3ca6f34c87 is described below

commit 3ca6f34c87b1e09d5f1302dc7ef5c18e4ca62b16
Author: yinzhijian <373141...@qq.com>
AuthorDate: Mon Aug 29 12:09:48 2022 +0800

    [fix](view) Fix view not showing specific lengths for varchar type (#12107)
---
 .../org/apache/doris/analysis/BaseViewStmt.java    | 21 ++++++----
 .../data/correctness/test_view_varchar_length.out  |  4 ++
 .../correctness/test_view_varchar_length.groovy    | 48 ++++++++++++++++++++++
 3 files changed, 66 insertions(+), 7 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseViewStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseViewStmt.java
index 6d6bdeaf11..d84a4e871f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseViewStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseViewStmt.java
@@ -18,8 +18,8 @@
 package org.apache.doris.analysis;
 
 import org.apache.doris.catalog.Column;
-import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
@@ -85,20 +85,27 @@ public class BaseViewStmt extends DdlStmt {
             if (cols.size() != viewDefStmt.getColLabels().size()) {
                 
ErrorReport.reportAnalysisException(ErrorCode.ERR_VIEW_WRONG_LIST);
             }
-            // TODO(zc): type
             for (int i = 0; i < cols.size(); ++i) {
-                PrimitiveType type = 
viewDefStmt.getBaseTblResultExprs().get(i).getType().getPrimitiveType();
-                Column col = new Column(cols.get(i).getColName(), 
ScalarType.createType(type));
+                Type type = 
viewDefStmt.getBaseTblResultExprs().get(i).getType();
+                Column col = new Column(cols.get(i).getColName(),
+                        ScalarType.createType(
+                                type.getPrimitiveType(),
+                                type.getLength(),
+                                type.getPrecision() != null ? 
type.getPrecision() : -1,
+                                type.getDecimalDigits() != null ? 
type.getDecimalDigits() : 0));
                 col.setComment(cols.get(i).getComment());
                 finalCols.add(col);
             }
         } else {
-            // TODO(zc): type
             for (int i = 0; i < viewDefStmt.getBaseTblResultExprs().size(); 
++i) {
-                PrimitiveType type = 
viewDefStmt.getBaseTblResultExprs().get(i).getType().getPrimitiveType();
+                Type type = 
viewDefStmt.getBaseTblResultExprs().get(i).getType();
                 finalCols.add(new Column(
                         viewDefStmt.getColLabels().get(i),
-                        ScalarType.createType(type)));
+                        ScalarType.createType(
+                                type.getPrimitiveType(),
+                                type.getLength(),
+                                type.getPrecision() != null ? 
type.getPrecision() : -1,
+                                type.getDecimalDigits() != null ? 
type.getDecimalDigits() : 0)));
             }
         }
         // Set for duplicate columns
diff --git a/regression-test/data/correctness/test_view_varchar_length.out 
b/regression-test/data/correctness/test_view_varchar_length.out
new file mode 100644
index 0000000000..2b67988f7f
--- /dev/null
+++ b/regression-test/data/correctness/test_view_varchar_length.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql --
+name   VARCHAR(32)     No      false   \N      
+
diff --git a/regression-test/suites/correctness/test_view_varchar_length.groovy 
b/regression-test/suites/correctness/test_view_varchar_length.groovy
new file mode 100644
index 0000000000..a639519cf1
--- /dev/null
+++ b/regression-test/suites/correctness/test_view_varchar_length.groovy
@@ -0,0 +1,48 @@
+// 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.
+
+
+/*
+The varchar column type of the view needs to be a specific number, not an 
asterisk
+Expect: varchar(32)
+Type before bug fix: varchar(*)
+*/
+ suite("test_view_varchar_length") {
+     sql """ DROP TABLE IF EXISTS T """
+     sql """
+         CREATE TABLE `T` (
+             `id` int,
+             `name` varchar(32) 
+         ) ENGINE=OLAP
+         COMMENT "OLAP"
+         DISTRIBUTED BY HASH(`id`) BUCKETS 1
+         PROPERTIES (
+             "replication_allocation" = "tag.location.default: 1",
+             "in_memory" = "false",
+             "storage_format" = "V2"
+         );
+     """
+     sql "drop view if exists V;"
+     sql """
+         create view V as select name from T;
+     """
+
+     qt_sql """
+         desc V;
+     """
+ }
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to