从Spark SQL生成SQL

瓦迪姆

我有一个DataFrameScala代码,Spark其中包含几个框架以及过滤器和动态部分。

是否可以生成和编写日志以记录经典SQL代码来控制流程?

        val target = List(
            ("0", "0", "Orange", "2020-03-10")
        ).toDF("id", "new_id", "name", "process_date")
    
    
    ....
    dynamic part of code
    ....
    
    increment.as("i")
            .join(target.as("t"), $"t.id" === $"i.id", "left")
            .select(selectFields: _*)

我想获得类似这样的日志

    select field1, field2, ....
    from increment i join target t where t.id = i.id
呼叫

也许您可以尝试在查询执行后立即写入日志本身。

类似于以下示例:

import org.apache.log4j.{Level, Logger}

Logger.getRootLogger.setLevel(Level.ERROR)
// your code here
increment.as("i")
        .join(target.as("t"), $"t.id" === $"i.id", "left")
        .select(selectFields: _*)
Logger.getRootLogger.error("""SELECT column1, column2, column3 FROM table JOIN table1 ON(id = id1) WHERE column3 = .....GROUP BY ....""")

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章