Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 38183200C77 for ; Mon, 1 May 2017 19:42:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 36A4E160BA0; Mon, 1 May 2017 17:42:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7E059160BAE for ; Mon, 1 May 2017 19:42:07 +0200 (CEST) Received: (qmail 17475 invoked by uid 500); 1 May 2017 17:42:06 -0000 Mailing-List: contact issues-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list issues@drill.apache.org Received: (qmail 17466 invoked by uid 99); 1 May 2017 17:42:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 May 2017 17:42:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 3AC96188C41 for ; Mon, 1 May 2017 17:42:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id crlaca57APxn for ; Mon, 1 May 2017 17:42:05 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C4D0B5FCE3 for ; Mon, 1 May 2017 17:42:04 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 507FCE05B1 for ; Mon, 1 May 2017 17:42:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1001D21DE1 for ; Mon, 1 May 2017 17:42:04 +0000 (UTC) Date: Mon, 1 May 2017 17:42:04 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@drill.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DRILL-5419) Calculate return string length for literals & some string functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 01 May 2017 17:42:08 -0000 [ https://issues.apache.org/jira/browse/DRILL-5419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15991159#comment-15991159 ] ASF GitHub Bot commented on DRILL-5419: --------------------------------------- Github user jinfengni commented on a diff in the pull request: https://github.com/apache/drill/pull/819#discussion_r114162499 --- Diff: common/src/main/java/org/apache/drill/common/types/Types.java --- @@ -636,43 +658,63 @@ public static String toString(final MajorType type) { /** * Get the precision of given type. - * @param majorType - * @return + * + * @param majorType major type + * @return precision value */ public static int getPrecision(MajorType majorType) { - MinorType type = majorType.getMinorType(); - - if (type == MinorType.VARBINARY || type == MinorType.VARCHAR) { - return 65536; - } - if (majorType.hasPrecision()) { return majorType.getPrecision(); } - return 0; + return isScalarStringType(majorType) ? MAX_VARCHAR_LENGTH : UNDEFINED; --- End diff -- The way this PR calculates the maximum length is not from "guess". The metadata information leveraged in this PR is in the "query" itself ( the function appearing in the query, or the string literal in the query). It does not apply to all the queries; only when the query provides enough information Drill will calculate the maximum length. In all other cases, Drill will perform same as before. The maximum length (L1) calculated in this PR is different different from what you describe in the case of scanner (L2). L2 <= L1. In the example of scanner with no metadata available, there would be no schema change; the precision is unset in type field, same as before. @arina-ielchiieva can correct me if my understanding is wrong. > Calculate return string length for literals & some string functions > ------------------------------------------------------------------- > > Key: DRILL-5419 > URL: https://issues.apache.org/jira/browse/DRILL-5419 > Project: Apache Drill > Issue Type: Bug > Affects Versions: 1.9.0 > Reporter: Arina Ielchiieva > Assignee: Arina Ielchiieva > Attachments: version_with_cast.JPG > > > Though Drill is schema-less and cannot determine in advance what the length of the column should be but if query has an explicit type/length specified, Drill should return correct column length. > For example, JDBC / ODBC Driver is ALWAYS returning 64K as the length of a varchar or char even if casts are applied. > Changes: > *LITERALS* > String literals length is the same as actual literal length. > Example: for 'aaa' return length is 3. > *CAST* > Return length is the one indicated in cast expression. This also applies when user has created view where each string columns was casted to varchar with some specific length. > This length will be returned to the user without need to apply cast one more time. Below mentioned functions can take leverage of underlying varchar length and calculate return length. > *LOWER, UPPER, INITCAP, REVERSE, FIRST_VALUE, LAST_VALUE* > Return length is underlying column length, i.e. if column is known, the same length will be returned. > Example: > lower(cast(col as varchar(30))) will return 30. > lower(col) will return max varchar length, since we don't know actual column length. > *LAG, LEAD* > Return length is underlying column length but column type will be nullable. > *LPAD, RPAD* > Pads the string to the length specified. Return length is this specified length. > *CONCAT, CONCAT OPERATOR (||)* > Return length is sum of underlying columns length. If length is greater then varchar max length, varchar max length is returned. > *SUBSTR, SUBSTRING, LEFT, RIGHT* > Calculates return length according to each function substring rules, for example, taking into account how many char should be substracted. > *IF EXPRESSIONS (CASE STATEMENT, COALESCE), UNION OPERATOR* > When combining string columns with different length, return length is max from source columns. -- This message was sent by Atlassian JIRA (v6.3.15#6346)