--- layout: global title: "Migration Guide: SQL, Datasets and DataFrame" displayTitle: "Migration Guide: SQL, Datasets and DataFrame" license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --- * Table of contents {:toc} ## Upgrading from Spark SQL 2.4 to 3.0 - In Spark 3.0, the deprecated methods `SQLContext.createExternalTable` and `SparkSession.createExternalTable` have been removed in favor of its replacement, `createTable`. - In Spark 3.0, the deprecated `HiveContext` class has been removed. Use `SparkSession.builder.enableHiveSupport()` instead. - Since Spark 3.0, configuration `spark.sql.crossJoin.enabled` become internal configuration, and is true by default, so by default spark won't raise exception on sql with implicit cross join. - Since Spark 3.0, we reversed argument order of the trim function from `TRIM(trimStr, str)` to `TRIM(str, trimStr)` to be compatible with other databases. - In Spark version 2.4 and earlier, SQL queries such as `FROM
Operation | Result prior to Spark 3.0 | Result starting Spark 3.0 |
---|---|---|
CAST('infinity' AS DOUBLE) CAST('+infinity' AS DOUBLE) CAST('inf' AS DOUBLE) CAST('+inf' AS DOUBLE) |
NULL | Double.PositiveInfinity |
CAST('-infinity' AS DOUBLE) CAST('-inf' AS DOUBLE) |
NULL | Double.NegativeInfinity |
CAST('infinity' AS FLOAT) CAST('+infinity' AS FLOAT) CAST('inf' AS FLOAT) CAST('+inf' AS FLOAT) |
NULL | Float.PositiveInfinity |
CAST('-infinity' AS FLOAT) CAST('-inf' AS FLOAT) |
NULL | Float.NegativeInfinity |
CAST('nan' AS DOUBLE) | NULL | Double.NaN |
CAST('nan' AS FLOAT) | NULL | Float.NaN |
Query | Spark 2.3 or Prior | Spark 2.4 | Remarks |
---|---|---|---|
SELECT array_contains(array(1), 1.34D);
|
true
|
false
|
In Spark 2.4, left and right parameters are promoted to array type of double type and double type respectively. |
SELECT array_contains(array(1), '1');
|
true
|
AnalysisException is thrown.
|
Explicit cast can be used in arguments to avoid the exception. In Spark 2.4, AnalysisException is thrown since integer type can not be promoted to string type in a loss-less manner.
|
SELECT array_contains(array(1), 'anystring');
|
null
|
AnalysisException is thrown.
|
Explicit cast can be used in arguments to avoid the exception. In Spark 2.4, AnalysisException is thrown since integer type can not be promoted to string type in a loss-less manner.
|
InputA \ InputB | NullType | IntegerType | LongType | DecimalType(38,0)* | DoubleType | DateType | TimestampType | StringType |
---|---|---|---|---|---|---|---|---|
NullType | NullType | IntegerType | LongType | DecimalType(38,0) | DoubleType | DateType | TimestampType | StringType |
IntegerType | IntegerType | IntegerType | LongType | DecimalType(38,0) | DoubleType | StringType | StringType | StringType |
LongType | LongType | LongType | LongType | DecimalType(38,0) | StringType | StringType | StringType | StringType |
DecimalType(38,0)* | DecimalType(38,0) | DecimalType(38,0) | DecimalType(38,0) | DecimalType(38,0) | StringType | StringType | StringType | StringType |
DoubleType | DoubleType | DoubleType | StringType | StringType | DoubleType | StringType | StringType | StringType |
DateType | DateType | StringType | StringType | StringType | StringType | DateType | TimestampType | StringType |
TimestampType | TimestampType | StringType | StringType | StringType | StringType | TimestampType | TimestampType | StringType |
StringType | StringType | StringType | StringType | StringType | StringType | StringType | StringType | StringType |