rahil-c commented on code in PR #18432:
URL: https://github.com/apache/hudi/pull/18432#discussion_r3023883945
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieSparkBaseAnalysis.scala:
##########
@@ -310,6 +332,50 @@ case class ResolveReferences(spark: SparkSession) extends
Rule[LogicalPlan]
sparkAdapter.getCatalystPlanUtils.unapplyMergeIntoTable(plan)
}
+ private def resolveTableToDf(tableName: String): DataFrame = {
+ if (tableName.contains(StoragePath.SEPARATOR)) {
+ spark.read.format("hudi").load(tableName)
+ } else {
+ spark.table(tableName)
+ }
+ }
+
+ private def evaluateQueryVector(expr: Expression): Array[Double] = {
+ if (!expr.foldable) {
+ throw new HoodieAnalysisException(
+ s"Function '${HoodieVectorSearchTableValuedFunction.FUNC_NAME}': " +
+ "query vector must be a constant expression (e.g., ARRAY(1.0, 2.0,
3.0))")
+ }
+ val value = expr.eval(null)
+ if (value == null) {
+ throw new HoodieAnalysisException(
+ s"Function '${HoodieVectorSearchTableValuedFunction.FUNC_NAME}': query
vector cannot be null")
+ }
+
+ val arrayData = value.asInstanceOf[ArrayData]
+ val numElements = arrayData.numElements()
+ val elementType = expr.dataType.asInstanceOf[ArrayType].elementType
+ val result = new Array[Double](numElements)
+ var i = 0
+ elementType match {
+ case DoubleType =>
+ while (i < numElements) { result(i) = arrayData.getDouble(i); i += 1 }
+ case FloatType =>
+ while (i < numElements) { result(i) = arrayData.getFloat(i).toDouble;
i += 1 }
+ case IntegerType =>
+ while (i < numElements) { result(i) = arrayData.getInt(i).toDouble; i
+= 1 }
+ // Spark SQL infers untyped decimal literals (e.g. ARRAY(1.0, 0.5)) as
DecimalType,
+ // not DoubleType. Accept any DecimalType and convert to Double.
+ case d: DecimalType =>
Review Comment:
Currently for VECTOR we support only FLOAT, DOUBLE, INT8
https://github.com/apache/hudi/blob/master/hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java#L1831
so dont think LongType is relevant unless I am missing something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]