4paradigm / OpenMLDB

OpenMLDB is an open-source machine learning database that provides a feature platform computing consistent features for training and inference.
https://openmldb.ai
Apache License 2.0
1.6k stars 320 forks source link

cast string as date not support in offline #3684

Open lqy222 opened 10 months ago

lqy222 commented 10 months ago

select date("2020-05-22"); below SQL not support in offline mode

tobegit3hub commented 9 months ago

It is caused by not handling ExprType.kExprCast in ConstProjectPlan.

tobegit3hub commented 9 months ago

Since the offline output does not consist of column data, we need to fix the output of ConstProjectPlan first. Otherwise we can only get the output column name date("2020-05-22") but no exactly data.

+----------------+
|date(2020-05-22)|
+----------------+
+----------------+

Here is the simple code to reproduce the issue.

import com._4paradigm.openmldb.batch.SparkTestSuite
import com._4paradigm.openmldb.batch.api.OpenmldbSession
import com._4paradigm.openmldb.batch.end2end.DataUtil
import com._4paradigm.openmldb.batch.utils.SparkUtil

class TestProject extends SparkTestSuite {

  test("Test end2end window aggregation") {

    val spark = getSparkSession
    val sess = new OpenmldbSession(spark)

    val df = DataUtil.getTestDf(spark)

    sess.registerTable("t1", df)
    df.createOrReplaceTempView("t1")

    val sql2 = "SELECT date('2024-01-01') FROM t1"
    val sql3 = "select int(1.1)"
    val sql = "select date('2020-05-22')"

    val outputDf = sess.sql(sql)
    outputDf.show()
  }

}