Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
checkGlutenPlan[ProjectExecTransformer]
}

// cast(timestamp_ntz as string)
runQueryAndCompare("select cast(ts as string) from view") {
checkGlutenPlan[ProjectExecTransformer]
}

withSQLConf("spark.sql.session.timeZone" -> "Asia/Hong_Kong") {
val dstPath = dir.getAbsolutePath + "/dst_gap"
spark
Expand Down Expand Up @@ -661,6 +666,21 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
checkGlutenPlan[ProjectExecTransformer]
}
}

val strPath = dir.getAbsolutePath + "/str_view"
spark
.createDataset(inputs)
.toDF("str")
.coalesce(1)
.write
.mode("overwrite")
.parquet(strPath)
spark.read.parquet(strPath).createOrReplaceTempView("str_view")

// cast(varchar as timestamp_ntz)
runQueryAndCompare("select cast(str as timestamp_ntz) from str_view") {
checkGlutenPlan[ProjectExecTransformer]
}
}
}
}
5 changes: 4 additions & 1 deletion cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const TypePtr& fromType, const
return false;
}
if (toType->equivalent(*TIMESTAMP_UTC())) {
// Only supports from Timestamp to TimestampNTZ.
// Only supports from Timestamp or Varchar to TimestampNTZ.
if (fromType->isVarchar()) {
return true;
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, ShuffleEx
import org.apache.spark.sql.execution.joins._
import org.apache.spark.sql.execution.window.WindowExec
import org.apache.spark.sql.hive.HiveTableScanExecTransformer
import org.apache.spark.sql.types.{ArrayType, DataType, MapType, StructType, TimestampType}
import org.apache.spark.sql.types.{ArrayType, DataType, MapType, StringType, StructType, TimestampType}

object Validators {
implicit class ValidatorBuilderImplicits(builder: Validator.Builder) {
Expand Down Expand Up @@ -284,7 +284,9 @@ object Validators {
case Second(child, _) => containsNTZ(child.dataType)
case TimestampAdd(_, _, child, _) => containsNTZ(child.dataType)
case c: Cast if c.dataType == TimestampType => isNTZ(c.child.dataType)
case c: Cast if isNTZ(c.dataType) => c.child.dataType == TimestampType
case c: Cast if c.dataType == StringType => isNTZ(c.child.dataType)
case c: Cast if isNTZ(c.dataType) =>
c.child.dataType == TimestampType || c.child.dataType == StringType
case _ => false
}
}
Expand Down
Loading