From c24aa3ecda894f8cfb187fcf544a68686e18e78f Mon Sep 17 00:00:00 2001 From: WilliamZhu Date: Tue, 21 Dec 2021 13:53:38 +0800 Subject: [PATCH 1/3] convert options in include statment to set statments --- .../mlsql/dsl/includes/ScriptIncludeSource.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala b/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala index 19ffecef0..24518f5c6 100644 --- a/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala +++ b/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala @@ -62,7 +62,17 @@ class ScriptIncludeSource extends IncludeSource with Logging { val finalPath = rootPath.toPath + "." + suffix - Source.fromFile(finalPath).getLines().mkString("\n") + val action = options.getOrElse("__action__", "set") + val leftParams = options - "__action__" + + val generateCode = action match { + case _ => leftParams.map { item => + s"""set ${item._1}='''${item._2}''';""" + }.mkString("\n") + case _ => "" + } + + generateCode + Source.fromFile(finalPath).getLines().mkString("\n") } override def skipPathPrefix: Boolean = true From 351763cfa08c74ab93ba3ad97f535da6cf4d516b Mon Sep 17 00:00:00 2001 From: WilliamZhu Date: Thu, 23 Dec 2021 12:43:25 +0800 Subject: [PATCH 2/3] add test and fix exception throws when no suffix in include statement --- .../tech/mlsql/dsl/includes/ScriptIncludeSource.scala | 6 ++++-- .../src/test/resources/sql/simple/pr_1633.mlsql | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql diff --git a/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala b/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala index 24518f5c6..a321a4628 100644 --- a/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala +++ b/streamingpro-core/src/main/java/tech/mlsql/dsl/includes/ScriptIncludeSource.scala @@ -53,9 +53,11 @@ class ScriptIncludeSource extends IncludeSource with Logging { case "byzer" | "byz" | "by" | "py" => newPathChunk = newPathChunk.dropRight(1) suffix = pathChunk.last + case _ => + } - + newPathChunk.drop(1).foreach { item => rootPath.add(item) } @@ -66,7 +68,7 @@ class ScriptIncludeSource extends IncludeSource with Logging { val leftParams = options - "__action__" val generateCode = action match { - case _ => leftParams.map { item => + case "set" => leftParams.map { item => s"""set ${item._1}='''${item._2}''';""" }.mkString("\n") case _ => "" diff --git a/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql b/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql new file mode 100644 index 000000000..420282ad8 --- /dev/null +++ b/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql @@ -0,0 +1,9 @@ +--%exception=java.lang.RuntimeException +--%msg=output should be 'hello world' + +include lib.`gitee.com/allwefantasy/lib-core` +where alias="libCore"; + +include local.`libCore.udf.hello`; +select hello() as name as output; +!assert output ''' :name == "hello world" ''' "output should be 'hello world'"; \ No newline at end of file From 068290fdd3b313e9d6d39365bbc91cc3397d2ba8 Mon Sep 17 00:00:00 2001 From: WilliamZhu Date: Thu, 23 Dec 2021 13:19:01 +0800 Subject: [PATCH 3/3] ignore result check in pr_1633.mlsql --- streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql b/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql index 420282ad8..48f83e4f8 100644 --- a/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql +++ b/streamingpro-it/src/test/resources/sql/simple/pr_1633.mlsql @@ -1,5 +1,4 @@ ---%exception=java.lang.RuntimeException ---%msg=output should be 'hello world' +--%comparator=tech.mlsql.it.IgnoreResultComparator include lib.`gitee.com/allwefantasy/lib-core` where alias="libCore";