Uploaded image for project: 'Kylin'
  1. Kylin
  2. KYLIN-5359

Kylin4 replace function expression convert error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • v4.0.1, v4.0.2
    • None
    • Query Engine
    • None

    Description

      查询语句形如:select name, replace(name, substring(name, 1, 1), '--') as new_name from LZ_TEST_YUFA 执行出错
      errorMsg:java.lang.ClassCastException: org.apache.spark.sql.Column cannot be cast to java.lang.String while executing SQL: "select * from (select name, replace(name, substring(name, 1, 1), '--') as new_name from LZ_TEST_YUFA) limit 50000

      原因:在ExpressionConverter中subtring返回的是一个column对象,而在replace转换中强制将函数参数转换为string

      // ExpressionConverter
      case "replace " =>
      	regexp_replace(k_lit(children.head),
      	  {color:red}children.apply(1).asInstanceOf[String],
      	  children.apply(2).asInstanceOf[String]{color})
      case "substring" | "substr" =>
      	if (children.length == 3) { //substr(str1,startPos,length)
      	 {color:red} k_lit(children.head)
      		.substr(k_lit(children.apply(1)), k_lit(children.apply(2))){color}
      	} else if (children.length == 2) { //substr(str1,startPos)
      	  k_lit(children.head).
      		substr(k_lit(children.apply(1)), k_lit(Int.MaxValue))
      	} else {
      	  throw new UnsupportedOperationException(
      		s"substring must provide three or two parameters under sparder")
      	}
      case "initcapb" =>
      	initcap(k_lit(children.head))
      


      Attachments

        1. image-2022-12-12-11-25-32-037.png
          27 kB
          Liu Zhao
        2. image-2022-12-12-11-25-41-178.png
          24 kB
          Liu Zhao

        Activity

          People

            zhaoliu4 Liu Zhao
            zhaoliu4 Liu Zhao
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: