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 63A98200C37 for ; Sun, 19 Mar 2017 19:48:47 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 62368160B7D; Sun, 19 Mar 2017 18:48:47 +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 AAB36160B6D for ; Sun, 19 Mar 2017 19:48:46 +0100 (CET) Received: (qmail 34052 invoked by uid 500); 19 Mar 2017 18:48:45 -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 34043 invoked by uid 99); 19 Mar 2017 18:48:45 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Mar 2017 18:48:45 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 5CE75C022F for ; Sun, 19 Mar 2017 18:48:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.651 X-Spam-Level: X-Spam-Status: No, score=0.651 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id B0ftUaXGPJbO for ; Sun, 19 Mar 2017 18:48:43 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 956E25FBE2 for ; Sun, 19 Mar 2017 18:48:42 +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 CB9C9E0054 for ; Sun, 19 Mar 2017 18:48:41 +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 7EE7824162 for ; Sun, 19 Mar 2017 18:48:41 +0000 (UTC) Date: Sun, 19 Mar 2017 18:48:41 +0000 (UTC) From: "Ruslan Dautkhanov (JIRA)" To: commits@airflow.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (AIRFLOW-1012) Add run_as_script option so jinja templating can be used for sql parameter MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 19 Mar 2017 18:48:47 -0000 Ruslan Dautkhanov created AIRFLOW-1012: ------------------------------------------ Summary: Add run_as_script option so jinja templating can be used for sql parameter Key: AIRFLOW-1012 URL: https://issues.apache.org/jira/browse/AIRFLOW-1012 Project: Apache Airflow Issue Type: Improvement Components: core, db Affects Versions: Airflow 1.8 Reporter: Ruslan Dautkhanov Assignee: Ruslan Dautkhanov It would be great to extend jinja templating to sql parameter for SQL Operators. With this improvement, it's possible to have extended Jinja template like below that generates multiple SQL statements that can be passed as a single 'sql' parameter, separated by ';' separator: {noformat} ) >> OracleOperator( task_id='give_owner_grants', oracle_conn_id=ora_conn1, run_as_script=True, sql=''' {% for role in ['CONNECT', 'RESOURCE'] %} GRANT {{ role }} TO {{ schema }}; {% endfor %} {% for create_grant in ['PROCEDURE', 'SEQUENCE', 'SESSION', 'TABLE', 'VIEW'] %} GRANT CREATE {{ create_grant }} TO {{ schema }}; {% endfor %} {% for tbsp in ['DISCOVER_MART_IDX01', 'DISCOVER_MART_TBS01', 'STAGING_NOLOG'] %} ALTER USER {{ schema }} QUOTA UNLIMITED ON {{ tbsp }}; {% endfor %} GRANT SELECT ANY TABLE TO {{ schema }}; GRANT EXECUTE ON SYS.DBMS_SESSION TO {{ schema }}; ''' ) >> DummyOperator(task_id='stop') {noformat} Notice there are three Jinja 'for' loops that generate multiple SQL DDL statements. Without this change, sql has to be passed as an Python array, and Jinja templating can't be used. I've tested this change with OracleOperator and works as expected. Notice `run_as_script=True` parameter. run_as_script defaults to False so this is a backward-compatible change. Most of the change is in airflow/hooks/dbapi_hook.py (very straightforward as run() already supports running an array of statements) and a light change of airflow/operators/oracle_operator.py - so this change can be easily applied to other sql operators. -- This message was sent by Atlassian JIRA (v6.3.15#6346)