Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnavBalyan committed Mar 11, 2025
1 parent 257dbc6 commit 7659f0f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/
package org.apache.spark.sql.catalyst.expressions

import org.apache.gluten.execution.VeloxWholeStageTransformerSuite

import org.apache.spark.sql.catalyst.util.DateTimeTestUtils.UTC_OPT
import org.apache.spark.sql.types._

import java.sql.Timestamp
import java.util.TimeZone

class VeloxCastSuite extends VeloxWholeStageTransformerSuite with ExpressionEvalHelper {
def cast(v: Any, targetType: DataType, timeZoneId: Option[String] = None): Cast = {
v match {
case lit: Expression =>
logDebug(s"Cast from: ${lit.dataType.typeName}, to: ${targetType.typeName}")
Cast(lit, targetType, timeZoneId)
case _ =>
val lit = Literal(v)
logDebug(s"Cast from: ${lit.dataType.typeName}, to: ${targetType.typeName}")
Cast(lit, targetType, timeZoneId)
}
}

test("cast binary to string type") {

val testCases = Seq(
("Hello, World!".getBytes, "Hello, World!"),
("12345".getBytes, "12345"),
("".getBytes, ""),
("Some special characters: !@#$%^&*()".getBytes, "Some special characters: !@#$%^&*()"),
("Line\nbreak".getBytes, "Line\nbreak")
)

for ((binaryValue, expectedString) <- testCases) {
checkEvaluation(cast(cast(binaryValue, BinaryType), StringType), expectedString)
}
}

override protected val resourcePath: String = "N/A"
override protected val fileFormat: String = "N/A"
}
5 changes: 4 additions & 1 deletion cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const TypePtr& fromType, const
// 3. Timestamp to most categories except few supported types is not allowed.
// 4. Certain complex types are not allowed.

auto fromKind = fromType->kind();
auto toKind = toType->kind();

// Don't support isIntervalYearMonth.
if (fromType->isIntervalYearMonth() || toType->isIntervalYearMonth()) {
LOG_VALIDATION_MSG("Casting involving INTERVAL_YEAR_MONTH is not supported.");
Expand All @@ -275,7 +278,7 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const TypePtr& fromType, const
}

// Limited support for Complex types.
if (fromType->isArray() || fromType->isMap() || fromType->isRow() || fromType->isVarbinary()) {
if (fromType->isArray() || fromType->isMap() || fromType->isRow() || (fromType->isVarbinary() && toKind != TypeKind::VARCHAR) {
LOG_VALIDATION_MSG("Casting from " + fromType->toString() + " is not currently supported.");
return false;
}
Expand Down

0 comments on commit 7659f0f

Please sign in to comment.