Skip to content
Snippets Groups Projects
  1. Oct 20, 2016
    • Wenchen Fan's avatar
      [SPARK-18029][SQL] PruneFileSourcePartitions should not change the output of LogicalRelation · 57e97fcb
      Wenchen Fan authored
      ## What changes were proposed in this pull request?
      
      In `PruneFileSourcePartitions`, we will replace the `LogicalRelation` with a pruned one. However, this replacement may change the output of the `LogicalRelation` if it doesn't have `expectedOutputAttributes`. This PR fixes it.
      
      ## How was this patch tested?
      
      the new `PruneFileSourcePartitionsSuite`
      
      Author: Wenchen Fan <wenchen@databricks.com>
      
      Closes #15569 from cloud-fan/partition-bug.
      57e97fcb
    • Shixiong Zhu's avatar
      [SPARK-18030][TESTS] Adds more checks to collect more info about FileStreamSourceSuite failure · 1bb99c48
      Shixiong Zhu authored
      ## What changes were proposed in this pull request?
      
      My hunch is `mkdirs` fails. Just add more checks to collect more info.
      
      ## How was this patch tested?
      
      Jenkins
      
      Author: Shixiong Zhu <shixiong@databricks.com>
      
      Closes #15577 from zsxwing/SPARK-18030-debug.
      1bb99c48
    • Reynold Xin's avatar
      [SPARK-18021][SQL] Refactor file name specification for data sources · 7f9ec19e
      Reynold Xin authored
      ## What changes were proposed in this pull request?
      Currently each data source OutputWriter is responsible for specifying the entire file name for each file output. This, however, does not make any sense because we rely on file naming schemes for certain behaviors in Spark SQL, e.g. bucket id. The current approach allows individual data sources to break the implementation of bucketing.
      
      On the flip side, we also don't want to move file naming entirely out of data sources, because different data sources do want to specify different extensions.
      
      This patch divides file name specification into two parts: the first part is a prefix specified by the caller of OutputWriter (in WriteOutput), and the second part is the suffix that can be specified by the OutputWriter itself. Note that a side effect of this change is that now all file based data sources also support bucketing automatically.
      
      There are also some other minor cleanups:
      
      - Removed the UUID passed through generic Configuration string
      - Some minor rewrites for better clarity
      - Renamed "path" in multiple places to "stagingDir", to more accurately reflect its meaning
      
      ## How was this patch tested?
      This should be covered by existing data source tests.
      
      Author: Reynold Xin <rxin@databricks.com>
      
      Closes #15562 from rxin/SPARK-18021.
      7f9ec19e
    • Koert Kuipers's avatar
      [SPARK-15780][SQL] Support mapValues on KeyValueGroupedDataset · 84b245f2
      Koert Kuipers authored
      ## What changes were proposed in this pull request?
      
      Add mapValues to KeyValueGroupedDataset
      
      ## How was this patch tested?
      
      New test in DatasetSuite for groupBy function, mapValues, flatMap
      
      Author: Koert Kuipers <koert@tresata.com>
      
      Closes #13526 from koertkuipers/feat-keyvaluegroupeddataset-mapvalues.
      84b245f2
    • Tejas Patil's avatar
      [SPARK-17698][SQL] Join predicates should not contain filter clauses · fb0894b3
      Tejas Patil authored
      ## What changes were proposed in this pull request?
      
      Jira : https://issues.apache.org/jira/browse/SPARK-17698
      
      `ExtractEquiJoinKeys` is incorrectly using filter predicates as the join condition for joins. `canEvaluate` [0] tries to see if the an `Expression` can be evaluated using output of a given `Plan`. In case of filter predicates (eg. `a.id='1'`), the `Expression` passed for the right hand side (ie. '1' ) is a `Literal` which does not have any attribute references. Thus `expr.references` is an empty set which theoretically is a subset of any set. This leads to `canEvaluate` returning `true` and `a.id='1'` is treated as a join predicate. While this does not lead to incorrect results but in case of bucketed + sorted tables, we might miss out on avoiding un-necessary shuffle + sort. See example below:
      
      [0] : https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala#L91
      
      eg.
      
      ```
      val df = (1 until 10).toDF("id").coalesce(1)
      hc.sql("DROP TABLE IF EXISTS table1").collect
      df.write.bucketBy(8, "id").sortBy("id").saveAsTable("table1")
      hc.sql("DROP TABLE IF EXISTS table2").collect
      df.write.bucketBy(8, "id").sortBy("id").saveAsTable("table2")
      
      sqlContext.sql("""
        SELECT a.id, b.id
        FROM table1 a
        FULL OUTER JOIN table2 b
        ON a.id = b.id AND a.id='1' AND b.id='1'
      """).explain(true)
      ```
      
      BEFORE: This is doing shuffle + sort over table scan outputs which is not needed as both tables are bucketed and sorted on the same columns and have same number of buckets. This should be a single stage job.
      
      ```
      SortMergeJoin [id#38, cast(id#38 as double), 1.0], [id#39, 1.0, cast(id#39 as double)], FullOuter
      :- *Sort [id#38 ASC NULLS FIRST, cast(id#38 as double) ASC NULLS FIRST, 1.0 ASC NULLS FIRST], false, 0
      :  +- Exchange hashpartitioning(id#38, cast(id#38 as double), 1.0, 200)
      :     +- *FileScan parquet default.table1[id#38] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table1, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>
      +- *Sort [id#39 ASC NULLS FIRST, 1.0 ASC NULLS FIRST, cast(id#39 as double) ASC NULLS FIRST], false, 0
         +- Exchange hashpartitioning(id#39, 1.0, cast(id#39 as double), 200)
            +- *FileScan parquet default.table2[id#39] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table2, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>
      ```
      
      AFTER :
      
      ```
      SortMergeJoin [id#32], [id#33], FullOuter, ((cast(id#32 as double) = 1.0) && (cast(id#33 as double) = 1.0))
      :- *FileScan parquet default.table1[id#32] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table1, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>
      +- *FileScan parquet default.table2[id#33] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table2, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>
      ```
      
      ## How was this patch tested?
      
      - Added a new test case for this scenario : `SPARK-17698 Join predicates should not contain filter clauses`
      - Ran all the tests in `BucketedReadSuite`
      
      Author: Tejas Patil <tejasp@fb.com>
      
      Closes #15272 from tejasapatil/SPARK-17698_join_predicate_filter_clause.
      fb0894b3
    • Dilip Biswal's avatar
      [SPARK-17860][SQL] SHOW COLUMN's database conflict check should respect case... · e895bc25
      Dilip Biswal authored
      [SPARK-17860][SQL] SHOW COLUMN's database conflict check should respect case sensitivity configuration
      
      ## What changes were proposed in this pull request?
      SHOW COLUMNS command validates the user supplied database
      name with database name from qualified table name name to make
      sure both of them are consistent. This comparison should respect
      case sensitivity.
      
      ## How was this patch tested?
      Added tests in DDLSuite and existing tests were moved to use new sql based test infrastructure.
      
      Author: Dilip Biswal <dbiswal@us.ibm.com>
      
      Closes #15423 from dilipbiswal/dkb_show_column_fix.
      e895bc25
    • Dongjoon Hyun's avatar
      [SPARK-17796][SQL] Support wildcard character in filename for LOAD DATA LOCAL INPATH · 986a3b8b
      Dongjoon Hyun authored
      ## What changes were proposed in this pull request?
      
      Currently, Spark 2.0 raises an `input path does not exist` AnalysisException if the file name contains '*'. It is misleading since it occurs when there exist some matched files. Also, it was a supported feature in Spark 1.6.2. This PR aims to support wildcard characters in filename for `LOAD DATA LOCAL INPATH` SQL command like Spark 1.6.2.
      
      **Reported Error Scenario**
      ```scala
      scala> sql("CREATE TABLE t(a string)")
      res0: org.apache.spark.sql.DataFrame = []
      
      scala> sql("LOAD DATA LOCAL INPATH '/tmp/x*' INTO TABLE t")
      org.apache.spark.sql.AnalysisException: LOAD DATA input path does not exist: /tmp/x*;
      ```
      
      ## How was this patch tested?
      
      Pass the Jenkins test with a new test case.
      
      Author: Dongjoon Hyun <dongjoon@apache.org>
      
      Closes #15376 from dongjoon-hyun/SPARK-17796.
      Unverified
      986a3b8b
    • Eric Liang's avatar
      [SPARK-17991][SQL] Enable metastore partition pruning by default. · 4bd17c46
      Eric Liang authored
      ## What changes were proposed in this pull request?
      
      This should apply to non-converted metastore relations. WIP to see if this causes any test failures.
      
      ## How was this patch tested?
      
      Existing tests.
      
      Author: Eric Liang <ekl@databricks.com>
      
      Closes #15475 from ericl/try-enabling-pruning.
      4bd17c46
    • Reynold Xin's avatar
      [SPARK-18012][SQL] Simplify WriterContainer · f313117b
      Reynold Xin authored
      ## What changes were proposed in this pull request?
      This patch refactors WriterContainer to simplify the logic and make control flow more obvious.The previous code setup made it pretty difficult to track the actual dependencies on variables and setups because the driver side and the executor side were using the same set of variables.
      
      ## How was this patch tested?
      N/A - this should be covered by existing tests.
      
      Author: Reynold Xin <rxin@databricks.com>
      
      Closes #15551 from rxin/writercontainer-refactor.
      f313117b
  2. Oct 19, 2016
    • hyukjinkwon's avatar
      [SPARK-17989][SQL] Check ascendingOrder type in sort_array function rather... · 4b2011ec
      hyukjinkwon authored
      [SPARK-17989][SQL] Check ascendingOrder type in sort_array function rather than throwing ClassCastException
      
      ## What changes were proposed in this pull request?
      
      This PR proposes to check the second argument, `ascendingOrder`  rather than throwing `ClassCastException` exception message.
      
      ```sql
      select sort_array(array('b', 'd'), '1');
      ```
      
      **Before**
      
      ```
      16/10/19 13:16:08 ERROR SparkSQLDriver: Failed in [select sort_array(array('b', 'd'), '1')]
      java.lang.ClassCastException: org.apache.spark.unsafe.types.UTF8String cannot be cast to java.lang.Boolean
      	at scala.runtime.BoxesRunTime.unboxToBoolean(BoxesRunTime.java:85)
      	at org.apache.spark.sql.catalyst.expressions.SortArray.nullSafeEval(collectionOperations.scala:185)
      	at org.apache.spark.sql.catalyst.expressions.BinaryExpression.eval(Expression.scala:416)
      	at org.apache.spark.sql.catalyst.optimizer.ConstantFolding$$anonfun$apply$1$$anonfun$applyOrElse$1.applyOrElse(expressions.scala:50)
      	at org.apache.spark.sql.catalyst.optimizer.ConstantFolding$$anonfun$apply$1$$anonfun$applyOrElse$1.applyOrElse(expressions.scala:43)
      	at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$3.apply(TreeNode.scala:292)
      	at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$3.apply(TreeNode.scala:292)
      	at org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(TreeNode.scala:74)
      	at org.apache.spark.sql.catalyst.trees.TreeNode.transformDown(TreeNode.scala:291)
      	at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$transformDown$1.apply(TreeNode.scala:297)
      ```
      
      **After**
      
      ```
      Error in query: cannot resolve 'sort_array(array('b', 'd'), '1')' due to data type mismatch: Sort order in second argument requires a boolean literal.; line 1 pos 7;
      ```
      
      ## How was this patch tested?
      
      Unit test in `DataFrameFunctionsSuite`.
      
      Author: hyukjinkwon <gurwls223@gmail.com>
      
      Closes #15532 from HyukjinKwon/SPARK-17989.
      4b2011ec
  3. Oct 18, 2016
    • Wenchen Fan's avatar
      [SPARK-17873][SQL] ALTER TABLE RENAME TO should allow users to specify... · 4329c5ce
      Wenchen Fan authored
      [SPARK-17873][SQL] ALTER TABLE RENAME TO should allow users to specify database in destination table name(but have to be same as source table)
      
      ## What changes were proposed in this pull request?
      
      Unlike Hive, in Spark SQL, ALTER TABLE RENAME TO cannot move a table from one database to another(e.g. `ALTER TABLE db1.tbl RENAME TO db2.tbl2`), and will report error if the database in source table and destination table is different. So in #14955 , we forbid users to specify database of destination table in ALTER TABLE RENAME TO, to be consistent with other database systems and also make it easier to rename tables in non-current database, e.g. users can write `ALTER TABLE db1.tbl RENAME TO tbl2`, instead of `ALTER TABLE db1.tbl RENAME TO db1.tbl2`.
      
      However, this is a breaking change. Users may already have queries that specify database of destination table in ALTER TABLE RENAME TO.
      
      This PR reverts most of #14955 , and simplify the usage of ALTER TABLE RENAME TO by making database of source table the default database of destination table, instead of current database, so that users can still write `ALTER TABLE db1.tbl RENAME TO tbl2`, which is consistent with other databases like MySQL, Postgres, etc.
      
      ## How was this patch tested?
      
      The added back tests and some new tests.
      
      Author: Wenchen Fan <wenchen@databricks.com>
      
      Closes #15434 from cloud-fan/revert.
      4329c5ce
    • Eric Liang's avatar
      [SPARK-17980][SQL] Fix refreshByPath for converted Hive tables · 5f20ae03
      Eric Liang authored
      ## What changes were proposed in this pull request?
      
      There was a bug introduced in https://github.com/apache/spark/pull/14690 which broke refreshByPath with converted hive tables (though, it turns out it was very difficult to refresh converted hive tables anyways, since you had to specify the exact path of one of the partitions).
      
      This changes refreshByPath to invalidate by prefix instead of exact match, and fixes the issue.
      
      cc sameeragarwal for refreshByPath changes
      mallman
      
      ## How was this patch tested?
      
      Extended unit test.
      
      Author: Eric Liang <ekl@databricks.com>
      
      Closes #15521 from ericl/fix-caching.
      5f20ae03
    • Tathagata Das's avatar
      [SPARK-17731][SQL][STREAMING][FOLLOWUP] Refactored StreamingQueryListener APIs · 941b3f9a
      Tathagata Das authored
      ## What changes were proposed in this pull request?
      
      As per rxin request, here are further API changes
      - Changed `Stream(Started/Progress/Terminated)` events to `Stream*Event`
      - Changed the fields in `StreamingQueryListener.on***` from `query*` to `event`
      
      ## How was this patch tested?
      Existing unit tests.
      
      Author: Tathagata Das <tathagata.das1565@gmail.com>
      
      Closes #15530 from tdas/SPARK-17731-1.
      941b3f9a
    • hyukjinkwon's avatar
      [SPARK-17955][SQL] Make DataFrameReader.jdbc call DataFrameReader.format("jdbc").load · b3130c7b
      hyukjinkwon authored
      ## What changes were proposed in this pull request?
      
      This PR proposes to make `DataFrameReader.jdbc` call `DataFrameReader.format("jdbc").load` consistently with other APIs in `DataFrameReader`/`DataFrameWriter` and avoid calling `sparkSession.baseRelationToDataFrame(..)` here and there.
      
      The changes were mostly copied from `DataFrameWriter.jdbc()` which was recently updated.
      
      ```diff
      -    val params = extraOptions.toMap ++ connectionProperties.asScala.toMap
      -    val options = new JDBCOptions(url, table, params)
      -    val relation = JDBCRelation(parts, options)(sparkSession)
      -    sparkSession.baseRelationToDataFrame(relation)
      +    this.extraOptions = this.extraOptions ++ connectionProperties.asScala
      +    // explicit url and dbtable should override all
      +    this.extraOptions += ("url" -> url, "dbtable" -> table)
      +    format("jdbc").load()
      ```
      
      ## How was this patch tested?
      
      Existing tests should cover this.
      
      Author: hyukjinkwon <gurwls223@gmail.com>
      
      Closes #15499 from HyukjinKwon/SPARK-17955.
      b3130c7b
    • Eric Liang's avatar
      [SPARK-17974] try 2) Refactor FileCatalog classes to simplify the inheritance tree · 4ef39c2f
      Eric Liang authored
      ## What changes were proposed in this pull request?
      
      This renames `BasicFileCatalog => FileCatalog`, combines  `SessionFileCatalog` with `PartitioningAwareFileCatalog`, and removes the old `FileCatalog` trait.
      
      In summary,
      ```
      MetadataLogFileCatalog extends PartitioningAwareFileCatalog
      ListingFileCatalog extends PartitioningAwareFileCatalog
      PartitioningAwareFileCatalog extends FileCatalog
      TableFileCatalog extends FileCatalog
      ```
      
      (note that this is a re-submission of https://github.com/apache/spark/pull/15518 which got reverted)
      
      ## How was this patch tested?
      
      Existing tests
      
      Author: Eric Liang <ekl@databricks.com>
      
      Closes #15533 from ericl/fix-scalastyle-revert.
      4ef39c2f
    • hyukjinkwon's avatar
      [SPARK-17388] [SQL] Support for inferring type date/timestamp/decimal for partition column · 37686539
      hyukjinkwon authored
      ## What changes were proposed in this pull request?
      
      Currently, Spark only supports to infer `IntegerType`, `LongType`, `DoubleType` and `StringType`.
      
      `DecimalType` is being tried but it seems it never infers type as `DecimalType` as `DoubleType` is being tried first. Also, it seems `DateType` and `TimestampType` could be inferred.
      
      As far as I know, it is pretty common to use both for a partition column.
      
      This PR fixes the incorrect `DecimalType` try and also adds the support for both `DateType` and `TimestampType` for inferring partition column type.
      
      ## How was this patch tested?
      
      Unit tests in `ParquetPartitionDiscoverySuite`.
      
      Author: hyukjinkwon <gurwls223@gmail.com>
      
      Closes #14947 from HyukjinKwon/SPARK-17388.
      37686539
    • Wenchen Fan's avatar
      [SPARK-17899][SQL][FOLLOW-UP] debug mode should work for corrupted table · e59df62e
      Wenchen Fan authored
      ## What changes were proposed in this pull request?
      
      Debug mode should work for corrupted table, so that we can really debug
      
      ## How was this patch tested?
      
      new test in `MetastoreDataSourcesSuite`
      
      Author: Wenchen Fan <wenchen@databricks.com>
      
      Closes #15528 from cloud-fan/debug.
      e59df62e
    • Tathagata Das's avatar
      [SQL][STREAMING][TEST] Follow up to remove Option.contains for Scala 2.10 compatibility · a9e79a41
      Tathagata Das authored
      ## What changes were proposed in this pull request?
      
      Scala 2.10 does not have Option.contains, which broke Scala 2.10 build.
      
      ## How was this patch tested?
      Locally compiled and ran sql/core unit tests in 2.10
      
      Author: Tathagata Das <tathagata.das1565@gmail.com>
      
      Closes #15531 from tdas/metrics-flaky-test-fix-1.
      a9e79a41
    • Liwei Lin's avatar
      [SQL][STREAMING][TEST] Fix flaky tests in StreamingQueryListenerSuite · 7d878cf2
      Liwei Lin authored
      This work has largely been done by lw-lin in his PR #15497. This is a slight refactoring of it.
      
      ## What changes were proposed in this pull request?
      There were two sources of flakiness in StreamingQueryListener test.
      
      - When testing with manual clock, consecutive attempts to advance the clock can occur without the stream execution thread being unblocked and doing some work between the two attempts. Hence the following can happen with the current ManualClock.
      ```
      +-----------------------------------+--------------------------------+
      |      StreamExecution thread       |         testing thread         |
      +-----------------------------------+--------------------------------+
      |  ManualClock.waitTillTime(100) {  |                                |
      |        _isWaiting = true          |                                |
      |            wait(10)               |                                |
      |        still in wait(10)          |  if (_isWaiting) advance(100)  |
      |        still in wait(10)          |  if (_isWaiting) advance(200)  | <- this should be disallowed !
      |        still in wait(10)          |  if (_isWaiting) advance(300)  | <- this should be disallowed !
      |      wake up from wait(10)        |                                |
      |       current time is 600         |                                |
      |       _isWaiting = false          |                                |
      |  }                                |                                |
      +-----------------------------------+--------------------------------+
      ```
      
      - Second source of flakiness is that the adding data to memory stream may get processing in any trigger, not just the first trigger.
      
      My fix is to make the manual clock wait for the other stream execution thread to start waiting for the clock at the right wait start time. That is, `advance(200)` (see above) will wait for stream execution thread to complete the wait that started at time 0, and start a new wait at time 200 (i.e. time stamp after the previous `advance(100)`).
      
      In addition, since this is a feature that is solely used by StreamExecution, I removed all the non-generic code from ManualClock and put them in StreamManualClock inside StreamTest.
      
      ## How was this patch tested?
      Ran existing unit test MANY TIME in Jenkins
      
      Author: Tathagata Das <tathagata.das1565@gmail.com>
      Author: Liwei Lin <lwlin7@gmail.com>
      
      Closes #15519 from tdas/metrics-flaky-test-fix.
      7d878cf2
  4. Oct 17, 2016
    • Reynold Xin's avatar
    • Eric Liang's avatar
      [SPARK-17974] Refactor FileCatalog classes to simplify the inheritance tree · 8daa1a29
      Eric Liang authored
      ## What changes were proposed in this pull request?
      
      This renames `BasicFileCatalog => FileCatalog`, combines  `SessionFileCatalog` with `PartitioningAwareFileCatalog`, and removes the old `FileCatalog` trait.
      
      In summary,
      ```
      MetadataLogFileCatalog extends PartitioningAwareFileCatalog
      ListingFileCatalog extends PartitioningAwareFileCatalog
      PartitioningAwareFileCatalog extends FileCatalog
      TableFileCatalog extends FileCatalog
      ```
      
      cc cloud-fan mallman
      
      ## How was this patch tested?
      
      Existing tests
      
      Author: Eric Liang <ekl@databricks.com>
      
      Closes #15518 from ericl/refactor-session-file-catalog.
      8daa1a29
    • Dilip Biswal's avatar
      [SPARK-17620][SQL] Determine Serde by hive.default.fileformat when Creating Hive Serde Tables · 813ab5e0
      Dilip Biswal authored
      ## What changes were proposed in this pull request?
      Reopens the closed PR https://github.com/apache/spark/pull/15190
      (Please refer to the above link for review comments on the PR)
      
      Make sure the hive.default.fileformat is used to when creating the storage format metadata.
      
      Output
      ``` SQL
      scala> spark.sql("SET hive.default.fileformat=orc")
      res1: org.apache.spark.sql.DataFrame = [key: string, value: string]
      
      scala> spark.sql("CREATE TABLE tmp_default(id INT)")
      res2: org.apache.spark.sql.DataFrame = []
      ```
      Before
      ```SQL
      scala> spark.sql("DESC FORMATTED tmp_default").collect.foreach(println)
      ..
      [# Storage Information,,]
      [SerDe Library:,org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe,]
      [InputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcInputFormat,]
      [OutputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat,]
      [Compressed:,No,]
      [Storage Desc Parameters:,,]
      [  serialization.format,1,]
      ```
      After
      ```SQL
      scala> spark.sql("DESC FORMATTED tmp_default").collect.foreach(println)
      ..
      [# Storage Information,,]
      [SerDe Library:,org.apache.hadoop.hive.ql.io.orc.OrcSerde,]
      [InputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcInputFormat,]
      [OutputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat,]
      [Compressed:,No,]
      [Storage Desc Parameters:,,]
      [  serialization.format,1,]
      
      ```
      ## How was this patch tested?
      
      (Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)
      Added new tests to HiveDDLCommandSuite, SQLQuerySuite
      
      Author: Dilip Biswal <dbiswal@us.ibm.com>
      
      Closes #15495 from dilipbiswal/orc2.
      813ab5e0
    • gatorsmile's avatar
      [SPARK-17751][SQL] Remove spark.sql.eagerAnalysis and Output the Plan if... · d88a1bae
      gatorsmile authored
      [SPARK-17751][SQL] Remove spark.sql.eagerAnalysis and Output the Plan if Existed in AnalysisException
      
      ### What changes were proposed in this pull request?
      Dataset always does eager analysis now. Thus, `spark.sql.eagerAnalysis` is not used any more. Thus, we need to remove it.
      
      This PR also outputs the plan. Without the fix, the analysis error is like
      ```
      cannot resolve '`k1`' given input columns: [k, v]; line 1 pos 12
      ```
      
      After the fix, the analysis error becomes:
      ```
      org.apache.spark.sql.AnalysisException: cannot resolve '`k1`' given input columns: [k, v]; line 1 pos 12;
      'Project [unresolvedalias(CASE WHEN ('k1 = 2) THEN 22 WHEN ('k1 = 4) THEN 44 ELSE 0 END, None), v#6]
      +- SubqueryAlias t
         +- Project [_1#2 AS k#5, _2#3 AS v#6]
            +- LocalRelation [_1#2, _2#3]
      ```
      
      ### How was this patch tested?
      N/A
      
      Author: gatorsmile <gatorsmile@gmail.com>
      
      Closes #15316 from gatorsmile/eagerAnalysis.
      d88a1bae
    • Sital Kedia's avatar
      [SPARK-17839][CORE] Use Nio's directbuffer instead of BufferedInputStream in... · c7ac027d
      Sital Kedia authored
      [SPARK-17839][CORE] Use Nio's directbuffer instead of BufferedInputStream in order to avoid additional copy from os buffer cache to user buffer
      
      ## What changes were proposed in this pull request?
      
      Currently we use BufferedInputStream to read the shuffle file which copies the file content from os buffer cache to the user buffer. This adds additional latency in reading the spill files. We made a change to use java nio's direct buffer to read the spill files and for certain pipelines spilling significant amount of data, we see up to 7% speedup for the entire pipeline.
      
      ## How was this patch tested?
      Tested by running the job in the cluster and observed up to 7% speedup.
      
      Author: Sital Kedia <skedia@fb.com>
      
      Closes #15408 from sitalkedia/skedia/nio_spill_read.
      c7ac027d
    • Weiqing Yang's avatar
      [MINOR][SQL] Add prettyName for current_database function · 56b0f5f4
      Weiqing Yang authored
      ## What changes were proposed in this pull request?
      Added a `prettyname` for current_database function.
      
      ## How was this patch tested?
      Manually.
      
      Before:
      ```
      scala> sql("select current_database()").show
      +-----------------+
      |currentdatabase()|
      +-----------------+
      |          default|
      +-----------------+
      ```
      
      After:
      ```
      scala> sql("select current_database()").show
      +------------------+
      |current_database()|
      +------------------+
      |           default|
      +------------------+
      ```
      
      Author: Weiqing Yang <yangweiqing001@gmail.com>
      
      Closes #15506 from weiqingy/prettyName.
      56b0f5f4
  5. Oct 16, 2016
    • gatorsmile's avatar
      [SPARK-17947][SQL] Add Doc and Comment about spark.sql.debug · e18d02c5
      gatorsmile authored
      ### What changes were proposed in this pull request?
      Just document the impact of `spark.sql.debug`:
      
      When enabling the debug, Spark SQL internal table properties are not filtered out; however, some related DDL commands (e.g., Analyze Table and CREATE TABLE LIKE) might not work properly.
      
      ### How was this patch tested?
      N/A
      
      Author: gatorsmile <gatorsmile@gmail.com>
      
      Closes #15494 from gatorsmile/addDocForSQLDebug.
      e18d02c5
    • Dongjoon Hyun's avatar
      [SPARK-17819][SQL] Support default database in connection URIs for Spark Thrift Server · 59e3eb5a
      Dongjoon Hyun authored
      ## What changes were proposed in this pull request?
      
      Currently, Spark Thrift Server ignores the default database in URI. This PR supports that like the following.
      
      ```sql
      $ bin/beeline -u jdbc:hive2://localhost:10000 -e "create database testdb"
      $ bin/beeline -u jdbc:hive2://localhost:10000/testdb -e "create table t(a int)"
      $ bin/beeline -u jdbc:hive2://localhost:10000/testdb -e "show tables"
      ...
      +------------+--------------+--+
      | tableName  | isTemporary  |
      +------------+--------------+--+
      | t          | false        |
      +------------+--------------+--+
      1 row selected (0.347 seconds)
      $ bin/beeline -u jdbc:hive2://localhost:10000 -e "show tables"
      ...
      +------------+--------------+--+
      | tableName  | isTemporary  |
      +------------+--------------+--+
      +------------+--------------+--+
      No rows selected (0.098 seconds)
      ```
      
      ## How was this patch tested?
      
      Manual.
      
      Note: I tried to add a test case for this, but I cannot found a suitable testsuite for this. I'll add the testcase if some advice is given.
      
      Author: Dongjoon Hyun <dongjoon@apache.org>
      
      Closes #15399 from dongjoon-hyun/SPARK-17819.
      59e3eb5a
  6. Oct 15, 2016
    • Jun Kim's avatar
      [SPARK-17953][DOCUMENTATION] Fix typo in SparkSession scaladoc · 36d81c2c
      Jun Kim authored
      ## What changes were proposed in this pull request?
      
      ### Before:
      ```scala
      SparkSession.builder()
           .master("local")
           .appName("Word Count")
           .config("spark.some.config.option", "some-value").
           .getOrCreate()
      ```
      
      ### After:
      ```scala
      SparkSession.builder()
           .master("local")
           .appName("Word Count")
           .config("spark.some.config.option", "some-value")
           .getOrCreate()
      ```
      
      There was one unexpected dot!
      
      Author: Jun Kim <i2r.jun@gmail.com>
      
      Closes #15498 from tae-jun/SPARK-17953.
      36d81c2c
  7. Oct 14, 2016
    • Michael Allman's avatar
      [SPARK-16980][SQL] Load only catalog table partition metadata required to answer a query · 6ce1b675
      Michael Allman authored
      (This PR addresses https://issues.apache.org/jira/browse/SPARK-16980.)
      
      ## What changes were proposed in this pull request?
      
      In a new Spark session, when a partitioned Hive table is converted to use Spark's `HadoopFsRelation` in `HiveMetastoreCatalog`, metadata for every partition of that table are retrieved from the metastore and loaded into driver memory. In addition, every partition's metadata files are read from the filesystem to perform schema inference.
      
      If a user queries such a table with predicates which prune that table's partitions, we would like to be able to answer that query without consulting partition metadata which are not involved in the query. When querying a table with a large number of partitions for some data from a small number of partitions (maybe even a single partition), the current conversion strategy is highly inefficient. I suspect this scenario is not uncommon in the wild.
      
      In addition to being inefficient in running time, the current strategy is inefficient in its use of driver memory. When the sum of the number of partitions of all tables loaded in a driver reaches a certain level (somewhere in the tens of thousands), their cached data exhaust all driver heap memory in the default configuration. I suspect this scenario is less common (in that not too many deployments work with tables with tens of thousands of partitions), however this does illustrate how large the memory footprint of this metadata can be. With tables with hundreds or thousands of partitions, I would expect the `HiveMetastoreCatalog` table cache to represent a significant portion of the driver's heap space.
      
      This PR proposes an alternative approach. Basically, it makes four changes:
      
      1. It adds a new method, `listPartitionsByFilter` to the Catalyst `ExternalCatalog` trait which returns the partition metadata for a given sequence of partition pruning predicates.
      1. It refactors the `FileCatalog` type hierarchy to include a new `TableFileCatalog` to efficiently return files only for partitions matching a sequence of partition pruning predicates.
      1. It removes partition loading and caching from `HiveMetastoreCatalog`.
      1. It adds a new Catalyst optimizer rule, `PruneFileSourcePartitions`, which applies a plan's partition-pruning predicates to prune out unnecessary partition files from a `HadoopFsRelation`'s underlying file catalog.
      
      The net effect is that when a query over a partitioned Hive table is planned, the analyzer retrieves the table metadata from `HiveMetastoreCatalog`. As part of this operation, the `HiveMetastoreCatalog` builds a `HadoopFsRelation` with a `TableFileCatalog`. It does not load any partition metadata or scan any files. The optimizer prunes-away unnecessary table partitions by sending the partition-pruning predicates to the relation's `TableFileCatalog `. The `TableFileCatalog` in turn calls the `listPartitionsByFilter` method on its external catalog. This queries the Hive metastore, passing along those filters.
      
      As a bonus, performing partition pruning during optimization leads to a more accurate relation size estimate. This, along with c481bdf5, can lead to automatic, safe application of the broadcast optimization in a join where it might previously have been omitted.
      
      ## Open Issues
      
      1. This PR omits partition metadata caching. I can add this once the overall strategy for the cold path is established, perhaps in a future PR.
      1. This PR removes and omits partitioned Hive table schema reconciliation. As a result, it fails to find Parquet schema columns with upper case letters because of the Hive metastore's case-insensitivity. This issue may be fixed by #14750, but that PR appears to have stalled. ericl has contributed to this PR a workaround for Parquet wherein schema reconciliation occurs at query execution time instead of planning. Whether ORC requires a similar patch is an open issue.
      1. This PR omits an implementation of `listPartitionsByFilter` for the `InMemoryCatalog`.
      1. This PR breaks parquet log output redirection during query execution. I can work around this by running `Class.forName("org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat$")` first thing in a Spark shell session, but I haven't figured out how to fix this properly.
      
      ## How was this patch tested?
      
      The current Spark unit tests were run, and some ad-hoc tests were performed to validate that only the necessary partition metadata is loaded.
      
      Author: Michael Allman <michael@videoamp.com>
      Author: Eric Liang <ekl@databricks.com>
      Author: Eric Liang <ekhliang@gmail.com>
      
      Closes #14690 from mallman/spark-16980-lazy_partition_fetching.
      6ce1b675
    • Srinath Shankar's avatar
      [SPARK-17946][PYSPARK] Python crossJoin API similar to Scala · 2d96d35d
      Srinath Shankar authored
      ## What changes were proposed in this pull request?
      
      Add a crossJoin function to the DataFrame API similar to that in Scala. Joins with no condition (cartesian products) must be specified with the crossJoin API
      
      ## How was this patch tested?
      Added python tests to ensure that an AnalysisException if a cartesian product is specified without crossJoin(), and that cartesian products can execute if specified via crossJoin()
      
      (Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)
      (If this patch involves UI changes, please attach a screenshot; otherwise, remove this)
      
      Please review https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark before opening a pull request.
      
      Author: Srinath Shankar <srinath@databricks.com>
      
      Closes #15493 from srinathshankar/crosspython.
      2d96d35d
    • Reynold Xin's avatar
      [SPARK-17900][SQL] Graduate a list of Spark SQL APIs to stable · 72adfbf9
      Reynold Xin authored
      ## What changes were proposed in this pull request?
      This patch graduates a list of Spark SQL APIs and mark them stable.
      
      The following are marked stable:
      
      Dataset/DataFrame
      - functions, since 1.3
      - ColumnName, since 1.3
      - DataFrameNaFunctions, since 1.3.1
      - DataFrameStatFunctions, since 1.4
      - UserDefinedFunction, since 1.3
      - UserDefinedAggregateFunction, since 1.5
      - Window and WindowSpec, since 1.4
      
      Data sources:
      - DataSourceRegister, since 1.5
      - RelationProvider, since 1.3
      - SchemaRelationProvider, since 1.3
      - CreatableRelationProvider, since 1.3
      - BaseRelation, since 1.3
      - TableScan, since 1.3
      - PrunedScan, since 1.3
      - PrunedFilteredScan, since 1.3
      - InsertableRelation, since 1.3
      
      The following are kept experimental / evolving:
      
      Data sources:
      - CatalystScan (tied to internal logical plans so it is not stable by definition)
      
      Structured streaming:
      - all classes (introduced new in 2.0 and will likely change)
      
      Dataset typed operations (introduced in 1.6 and 2.0 and might change, although probability is low)
      - all typed methods on Dataset
      - KeyValueGroupedDataset
      - o.a.s.sql.expressions.javalang.typed
      - o.a.s.sql.expressions.scalalang.typed
      - methods that return typed Dataset in SparkSession
      
      We should discuss more whether we want to mark Dataset typed operations stable in 2.1.
      
      ## How was this patch tested?
      N/A - just annotation changes.
      
      Author: Reynold Xin <rxin@databricks.com>
      
      Closes #15469 from rxin/SPARK-17900.
      72adfbf9
    • Jeff Zhang's avatar
      [SPARK-11775][PYSPARK][SQL] Allow PySpark to register Java UDF · f00df40c
      Jeff Zhang authored
      Currently pyspark can only call the builtin java UDF, but can not call custom java UDF. It would be better to allow that. 2 benefits:
      * Leverage the power of rich third party java library
      * Improve the performance. Because if we use python UDF, python daemons will be started on worker which will affect the performance.
      
      Author: Jeff Zhang <zjffdu@apache.org>
      
      Closes #9766 from zjffdu/SPARK-11775.
      f00df40c
    • Nick Pentreath's avatar
      [SPARK-16063][SQL] Add storageLevel to Dataset · 5aeb7384
      Nick Pentreath authored
      [SPARK-11905](https://issues.apache.org/jira/browse/SPARK-11905
      
      ) added support for `persist`/`cache` for `Dataset`. However, there is no user-facing API to check if a `Dataset` is cached and if so what the storage level is. This PR adds `getStorageLevel` to `Dataset`, analogous to `RDD.getStorageLevel`.
      
      Updated `DatasetCacheSuite`.
      
      Author: Nick Pentreath <nickp@za.ibm.com>
      
      Closes #13780 from MLnick/ds-storagelevel.
      
      Signed-off-by: default avatarMichael Armbrust <michael@databricks.com>
      5aeb7384
    • Davies Liu's avatar
      [SPARK-17863][SQL] should not add column into Distinct · da9aeb0f
      Davies Liu authored
      ## What changes were proposed in this pull request?
      
      We are trying to resolve the attribute in sort by pulling up some column for grandchild into child, but that's wrong when the child is Distinct, because the added column will change the behavior of Distinct, we should not do that.
      
      ## How was this patch tested?
      
      Added regression test.
      
      Author: Davies Liu <davies@databricks.com>
      
      Closes #15489 from davies/order_distinct.
      da9aeb0f
    • Yin Huai's avatar
      Revert "[SPARK-17620][SQL] Determine Serde by hive.default.fileformat when... · 522dd0d0
      Yin Huai authored
      Revert "[SPARK-17620][SQL] Determine Serde by hive.default.fileformat when Creating Hive Serde Tables"
      
      This reverts commit 7ab86244.
      522dd0d0
    • Dilip Biswal's avatar
      [SPARK-17620][SQL] Determine Serde by hive.default.fileformat when Creating Hive Serde Tables · 7ab86244
      Dilip Biswal authored
      ## What changes were proposed in this pull request?
      Make sure the hive.default.fileformat is used to when creating the storage format metadata.
      
      Output
      ``` SQL
      scala> spark.sql("SET hive.default.fileformat=orc")
      res1: org.apache.spark.sql.DataFrame = [key: string, value: string]
      
      scala> spark.sql("CREATE TABLE tmp_default(id INT)")
      res2: org.apache.spark.sql.DataFrame = []
      ```
      Before
      ```SQL
      scala> spark.sql("DESC FORMATTED tmp_default").collect.foreach(println)
      ..
      [# Storage Information,,]
      [SerDe Library:,org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe,]
      [InputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcInputFormat,]
      [OutputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat,]
      [Compressed:,No,]
      [Storage Desc Parameters:,,]
      [  serialization.format,1,]
      ```
      After
      ```SQL
      scala> spark.sql("DESC FORMATTED tmp_default").collect.foreach(println)
      ..
      [# Storage Information,,]
      [SerDe Library:,org.apache.hadoop.hive.ql.io.orc.OrcSerde,]
      [InputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcInputFormat,]
      [OutputFormat:,org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat,]
      [Compressed:,No,]
      [Storage Desc Parameters:,,]
      [  serialization.format,1,]
      
      ```
      
      ## How was this patch tested?
      Added new tests to HiveDDLCommandSuite
      
      Author: Dilip Biswal <dbiswal@us.ibm.com>
      
      Closes #15190 from dilipbiswal/orc.
      7ab86244
    • Tathagata Das's avatar
      [TEST] Ignore flaky test in StreamingQueryListenerSuite · 05800b4b
      Tathagata Das authored
      ## What changes were proposed in this pull request?
      
      Ignoring the flaky test introduced in #15307
      
      https://amplab.cs.berkeley.edu/jenkins/job/spark-master-test-sbt-hadoop-2.7/1736/testReport/junit/org.apache.spark.sql.streaming/StreamingQueryListenerSuite/single_listener__check_trigger_statuses/
      
      Author: Tathagata Das <tathagata.das1565@gmail.com>
      
      Closes #15491 from tdas/metrics-flaky-test.
      05800b4b
    • Andrew Ash's avatar
      Typo: form -> from · fa37877a
      Andrew Ash authored
      ## What changes were proposed in this pull request?
      
      Minor typo fix
      
      ## How was this patch tested?
      
      Existing unit tests on Jenkins
      
      Author: Andrew Ash <andrew@andrewash.com>
      
      Closes #15486 from ash211/patch-8.
      Unverified
      fa37877a
    • wangzhenhua's avatar
      [SPARK-17073][SQL][FOLLOWUP] generate column-level statistics · 7486442f
      wangzhenhua authored
      ## What changes were proposed in this pull request?
      This pr adds some test cases for statistics: case sensitive column names, non ascii column names, refresh table, and also improves some documentation.
      
      ## How was this patch tested?
      add test cases
      
      Author: wangzhenhua <wangzhenhua@huawei.com>
      
      Closes #15360 from wzhfy/colStats2.
      7486442f
    • Wenchen Fan's avatar
      [SPARK-17903][SQL] MetastoreRelation should talk to external catalog instead of hive client · 2fb12b0a
      Wenchen Fan authored
      ## What changes were proposed in this pull request?
      
      `HiveExternalCatalog` should be the only interface to talk to the hive metastore. In `MetastoreRelation` we can just use `ExternalCatalog` instead of `HiveClient` to interact with hive metastore,  and add missing API in `ExternalCatalog`.
      
      ## How was this patch tested?
      
      existing tests.
      
      Author: Wenchen Fan <wenchen@databricks.com>
      
      Closes #15460 from cloud-fan/relation.
      2fb12b0a
Loading