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 09B7C200D5B for ; Wed, 29 Nov 2017 00:37:07 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 082C3160BE7; Tue, 28 Nov 2017 23:37:07 +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 2EF06160C15 for ; Wed, 29 Nov 2017 00:37:06 +0100 (CET) Received: (qmail 37401 invoked by uid 500); 28 Nov 2017 23:37:05 -0000 Mailing-List: contact commits-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list commits@airflow.incubator.apache.org Received: (qmail 37387 invoked by uid 99); 28 Nov 2017 23:37:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Nov 2017 23:37:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 58EF0C611E for ; Tue, 28 Nov 2017 23:37:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.011 X-Spam-Level: X-Spam-Status: No, score=-99.011 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KB_WAM_FROM_NAME_SINGLEWORD=0.2, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id H8G_pc5vrQT2 for ; Tue, 28 Nov 2017 23:37:03 +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 7E1F15F3F0 for ; Tue, 28 Nov 2017 23:37:02 +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 6AAA5E25A1 for ; Tue, 28 Nov 2017 23:37:01 +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 8ABFB241D6 for ; Tue, 28 Nov 2017 23:37:00 +0000 (UTC) Date: Tue, 28 Nov 2017 23:37:00 +0000 (UTC) From: "Mark S Weiss (JIRA)" To: commits@airflow.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (AIRFLOW-1862) redshift_to_s3_operator fails on BOOLEAN column in source table MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 28 Nov 2017 23:37:07 -0000 [ https://issues.apache.org/jira/browse/AIRFLOW-1862?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Mark S Weiss updated AIRFLOW-1862: ---------------------------------- Description: The {{airflow/operators/redshift_to_s3_operator}} module generates an {{UNLOAD}} query using an SQL fragment for the {{column_castings}} that is generated by this line: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L87 This is a bug, because a {{CAST()}} in Redshift on a column of type {{BOOLEAN}} will raise an error and abort execution of the SQL statement. The error raised is {{ERROR: cannot cast type boolean to character varying}}. This can be trivially verified in Redshift using the following code: my_db=# CREATE TABLE temp (BOOLEAN flag); my_db=# INSERT INTO temp (flag) VALUES(false); my_db=#SELECT CAST (flag AS text) FROM temp; ERROR: cannot cast type boolean to character varying The solution is to handle the case of {{BOOLEAN}} columns, by: Modifying the {{columns_query}} here https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L75 to also select column {{data_type}} Modify the expression here to use the {{data_type}} to generate a valid {{CAST}} here: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L87 I have implemented and locally tested this alternative, which I believe is both minimal in scope and robust in all cases, and will submit a pull request. column_castings = (', ').join(["CAST({0} AS text) AS {1}".format(columns[i], columns[i]) if types[i] != 'boolean' else "CAST(CAST({0} AS SMALLINT)AS text) AS {1}".format(columns[i], columns[i]) for i in xrange(len(columns))]) was: The {{airflow/operators/redshift_to_s3_operator}} module generates an {{UNLOAD}} query using an SQL fragment for the {{column_castings}} that is generated by this line: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L87 This is a bug, because a {{CAST()}} in Redshift on a column of type {{BOOLEAN}} will raise an error and abort execution of the SQL statement. The error raised is {{ERROR: cannot cast type boolean to character varying}}. This can be trivially verified in Redshift using the following code: my_db=# CREATE TABLE temp (BOOLEAN flag); my_db=# INSERT INTO temp (flag) VALUES(false); my_db=#SELECT CAST (flag AS text) FROM temp; ERROR: cannot cast type boolean to character varying The solution is to handle the case of {{BOOLEAN}} columns, by: Modifying the {{columns_query}} here https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L75 to also select column {{data_type}} Modify the expression here to use the {{data_type}} to generate a valid {{CAST}} here: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L87 I have implemented and locally tested this alternative, which I believe is both minimal in scope and robust in all cases, and will submit a pull request. column_castings = (', ').join(["CAST({0} AS text) AS {1}".format(columns[i], columns[i]) if types[i] != 'boolean' else "CAST(CAST({0} AS SMALLINT)AS text) AS {1}".format(columns[i], columns[i]) for i in xrange(len(columns))]) > redshift_to_s3_operator fails on BOOLEAN column in source table > --------------------------------------------------------------- > > Key: AIRFLOW-1862 > URL: https://issues.apache.org/jira/browse/AIRFLOW-1862 > Project: Apache Airflow > Issue Type: Bug > Components: redshift > Affects Versions: Airflow 1.8 > Reporter: Mark S Weiss > Assignee: Mark S Weiss > Labels: easyfix > Fix For: Airflow 1.8 > > > The {{airflow/operators/redshift_to_s3_operator}} module generates an {{UNLOAD}} query using an SQL fragment for the {{column_castings}} that is generated by this line: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L87 > This is a bug, because a {{CAST()}} in Redshift on a column of type {{BOOLEAN}} will raise an error and abort execution of the SQL statement. The error raised is {{ERROR: cannot cast type boolean to character varying}}. > This can be trivially verified in Redshift using the following code: > > my_db=# CREATE TABLE temp (BOOLEAN flag); > my_db=# INSERT INTO temp (flag) VALUES(false); > my_db=#SELECT CAST (flag AS text) FROM temp; > ERROR: cannot cast type boolean to character varying > > The solution is to handle the case of {{BOOLEAN}} columns, by: > Modifying the {{columns_query}} here https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L75 to also select column {{data_type}} > Modify the expression here to use the {{data_type}} to generate a valid {{CAST}} here: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/redshift_to_s3_operator.py#L87 > I have implemented and locally tested this alternative, which I believe is both minimal in scope and robust in all cases, and will submit a pull request. > > column_castings = (', ').join(["CAST({0} AS text) AS {1}".format(columns[i], columns[i]) > if types[i] != 'boolean' else > "CAST(CAST({0} AS SMALLINT)AS text) AS {1}".format(columns[i], columns[i]) > for i in xrange(len(columns))]) > -- This message was sent by Atlassian JIRA (v6.4.14#64029)