Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VL] Support casting varchar type to timestamp type #8357

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 15 additions & 11 deletions cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,29 +269,33 @@ bool SubstraitToVeloxPlanValidator::validateCast(
const auto& toType = SubstraitParser::parseType(castExpr.type());
core::TypedExprPtr input = exprConverter_->toVeloxExpr(castExpr.input(), inputType);

// Only support cast from date to timestamp
if (toType->kind() == TypeKind::TIMESTAMP && !input->type()->isDate()) {
LOG_VALIDATION_MSG(
"Casting from " + input->type()->toString() + " to " + toType->toString() + " is not supported.");
return false;
// Only support casting from date or varchar to timestamp.
switch (toType->kind()) {
case TypeKind::TIMESTAMP: {
if (!input->type()->isDate() && input->type()->kind() != TypeKind::VARCHAR) {
LOG_VALIDATION_MSG(
"Casting from " + input->type()->toString() + " to " + toType->toString() + " is not supported.");
return false;
}
}
default: {
}
}

if (toType->isIntervalYearMonth()) {
LOG_VALIDATION_MSG("Casting to " + toType->toString() + " is not supported.");
if (input->type()->isIntervalYearMonth() || toType->isIntervalYearMonth()) {
LOG_VALIDATION_MSG("Casting from/to IntervalYearMonthType is not supported.");
return false;
}

// Casting from some types is not supported. See CastExpr::applyPeeled.
if (input->type()->isDate()) {
// Only support cast date to varchar & timestamp
// Only support casting from date to varchar or timestamp
if (toType->kind() != TypeKind::VARCHAR && toType->kind() != TypeKind::TIMESTAMP) {
LOG_VALIDATION_MSG("Casting from DATE to " + toType->toString() + " is not supported.");
return false;
}
} else if (input->type()->isIntervalYearMonth()) {
LOG_VALIDATION_MSG("Casting from INTERVAL_YEAR_MONTH is not supported.");
return false;
}

switch (input->type()->kind()) {
case TypeKind::ARRAY:
case TypeKind::MAP:
Expand Down
4 changes: 2 additions & 2 deletions ep/build-velox/src/get_velox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

set -exu

VELOX_REPO=https://github.com/oap-project/velox.git
VELOX_BRANCH=2025_01_12
VELOX_REPO=https://github.com/philo-he/velox.git
VELOX_BRANCH=2025_01_12-v1
VELOX_HOME=""

OS=`uname -s`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class GlutenCastSuite extends CastSuite with GlutenTestsTrait {
val nts = sts + ".1"
val ts = withDefaultTimeZone(UTC)(Timestamp.valueOf(nts))

for (tz <- ALL_TIMEZONES) {
// SystemV timezones are a legacy way of specifying timezones in Unix-like OS.
// It is not supported by Velox.
for (tz <- ALL_TIMEZONES.filterNot(_.getId.contains("SystemV"))) {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> tz.getId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class GlutenCastSuite extends CastSuite with GlutenTestsTrait {
val nts = sts + ".1"
val ts = withDefaultTimeZone(UTC)(Timestamp.valueOf(nts))

for (tz <- ALL_TIMEZONES) {
// SystemV timezones are a legacy way of specifying timezones in Unix-like OS.
// It is not supported by Velox.
for (tz <- ALL_TIMEZONES.filterNot(_.getId.contains("SystemV"))) {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> tz.getId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class GlutenCastSuite extends CastSuiteBase with GlutenTestsTrait {
val nts = sts + ".1"
val ts = withDefaultTimeZone(UTC)(Timestamp.valueOf(nts))

for (tz <- ALL_TIMEZONES) {
// SystemV timezones are a legacy way of specifying timezones in Unix-like OS.
// It is not supported by Velox.
for (tz <- ALL_TIMEZONES.filterNot(_.getId.contains("SystemV"))) {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> tz.getId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class GlutenTryCastSuite extends TryCastSuite with GlutenTestsTrait {
val nts = sts + ".1"
val ts = withDefaultTimeZone(UTC)(Timestamp.valueOf(nts))

for (tz <- ALL_TIMEZONES) {
// SystemV timezones are a legacy way of specifying timezones in Unix-like OS.
// It is not supported by Velox.
for (tz <- ALL_TIMEZONES.filterNot(_.getId.contains("SystemV"))) {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> tz.getId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class GlutenCastSuite extends CastSuiteBase with GlutenTestsTrait {
val nts = sts + ".1"
val ts = withDefaultTimeZone(UTC)(Timestamp.valueOf(nts))

for (tz <- ALL_TIMEZONES) {
// SystemV timezones are a legacy way of specifying timezones in Unix-like OS.
// It is not supported by Velox.
for (tz <- ALL_TIMEZONES.filterNot(_.getId.contains("SystemV"))) {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> tz.getId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class GlutenTryCastSuite extends TryCastSuite with GlutenTestsTrait {
val nts = sts + ".1"
val ts = withDefaultTimeZone(UTC)(Timestamp.valueOf(nts))

for (tz <- ALL_TIMEZONES) {
// SystemV timezones are a legacy way of specifying timezones in Unix-like OS.
// It is not supported by Velox.
for (tz <- ALL_TIMEZONES.filterNot(_.getId.contains("SystemV"))) {
withSQLConf(
SQLConf.SESSION_LOCAL_TIMEZONE.key -> tz.getId
) {
Expand Down
Loading