[ https://issues.apache.org/jira/browse/SPARK-15916?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Cheng Lian updated SPARK-15916: ------------------------------- Description: A table from SQL server Northwind database was registered as a JDBC dataframe. A query was executed on Spark SQL, the {{northwind_dbo_Categories}} table is a temporary table which is a JDBC dataframe to {{\[northwind\].\[dbo\].\[Categories\]}} SQL server table: SQL executed on Spark sql context: {code:sql} SELECT CategoryID FROM northwind_dbo_Categories WHERE (CategoryID = 1 OR CategoryID = 2) AND CategoryName = 'Beverages' {code} Spark has done a proper predicate pushdown to JDBC, however parenthesis around two {{OR}} conditions was removed. Instead the following query was sent over JDBC to SQL Server: {code:sql} SELECT "CategoryID" FROM [northwind].[dbo].[Categories] WHERE (CategoryID = 1) OR (CategoryID = 2) AND CategoryName = 'Beverages' {code} As a result, the last two conditions (around the AND operator) were considered as the highest precedence: {{(CategoryID = 2) AND CategoryName = 'Beverages'}} Finally SQL Server has executed a query like this: {code:sql} SELECT "CategoryID" FROM [northwind].[dbo].[Categories] WHERE CategoryID = 1 OR (CategoryID = 2 AND CategoryName = 'Beverages') {code} was: A table from sql server Northwind database was registered as a JDBC dataframe. A query was executed on Spark SQL, the "northwind_dbo_Categories" table is a temporary table which is a JDBC dataframe to "[northwind].[dbo].[Categories]" sql server table: SQL executed on Spark sql context: SELECT CategoryID FROM northwind_dbo_Categories WHERE (CategoryID = 1 OR CategoryID = 2) AND CategoryName = 'Beverages' Spark has done a proper predicate pushdown to JDBC, however parenthesis around two OR conditions was removed. Instead the following query was sent over JDBC to SQL Server: SELECT "CategoryID" FROM [northwind].[dbo].[Categories] WHERE (CategoryID = 1) OR (CategoryID = 2) AND CategoryName = 'Beverages' As a result, the last two conditions (around the AND operator) were considered as the highest precedence: (CategoryID = 2) AND CategoryName = 'Beverages' Finally SQL Server has executed a query like this: SELECT "CategoryID" FROM [northwind].[dbo].[Categories] WHERE CategoryID = 1 OR (CategoryID = 2 AND CategoryName = 'Beverages') > JDBC AND/OR operator push down does not respect lower OR operator precedence > ---------------------------------------------------------------------------- > > Key: SPARK-15916 > URL: https://issues.apache.org/jira/browse/SPARK-15916 > Project: Spark > Issue Type: Bug > Components: SQL > Affects Versions: 2.0.0 > Reporter: Piotr Czarnas > Assignee: Hyukjin Kwon > Fix For: 2.0.0 > > > A table from SQL server Northwind database was registered as a JDBC dataframe. > A query was executed on Spark SQL, the {{northwind_dbo_Categories}} table is > a temporary table which is a JDBC dataframe to > {{\[northwind\].\[dbo\].\[Categories\]}} SQL server table: > SQL executed on Spark sql context: > {code:sql} > SELECT CategoryID FROM northwind_dbo_Categories > WHERE (CategoryID = 1 OR CategoryID = 2) AND CategoryName = 'Beverages' > {code} > Spark has done a proper predicate pushdown to JDBC, however parenthesis > around two {{OR}} conditions was removed. Instead the following query was > sent over JDBC to SQL Server: > {code:sql} > SELECT "CategoryID" FROM [northwind].[dbo].[Categories] WHERE (CategoryID = > 1) OR (CategoryID = 2) AND CategoryName = 'Beverages' > {code} > As a result, the last two conditions (around the AND operator) were > considered as the highest precedence: {{(CategoryID = 2) AND CategoryName = > 'Beverages'}} > Finally SQL Server has executed a query like this: > {code:sql} > SELECT "CategoryID" FROM [northwind].[dbo].[Categories] WHERE CategoryID = 1 > OR (CategoryID = 2 AND CategoryName = 'Beverages') > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org