From 0839e1c1a1821fb83bd0d5b561adf25d8fecab86 Mon Sep 17 00:00:00 2001 From: judy_0131 Date: Mon, 29 Jul 2019 13:52:19 +0800 Subject: [PATCH] fix putHiveQL bug --- .gitignore | 1 + .../cn/piflow/bundle/hive/PutHiveQL.scala | 20 +++++++------------ .../main/scala/cn/piflow/util/HdfsUtil.scala | 6 +++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 2c1c5b9..3f5ede5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ ### Scala template *.class *.log +*.iml /.idea/ .DS_Store diff --git a/piflow-bundle/src/main/scala/cn/piflow/bundle/hive/PutHiveQL.scala b/piflow-bundle/src/main/scala/cn/piflow/bundle/hive/PutHiveQL.scala index 9cf17f9..a59b010 100644 --- a/piflow-bundle/src/main/scala/cn/piflow/bundle/hive/PutHiveQL.scala +++ b/piflow-bundle/src/main/scala/cn/piflow/bundle/hive/PutHiveQL.scala @@ -25,19 +25,13 @@ class PutHiveQL extends ConfigurableStop { import scala.io.Source sql(sqlText= "use "+database) - var lines:String="" - //Source.fromFile(hiveQL_path).getLines().foreach(x=>{ - HdfsUtil.getLines(hiveQL_path).foreach(x => { - if(x.contains(";")){ - lines=lines+" "+x.replace(";","") - println(lines) - sql(sqlText = lines) - lines="" - }else{ - lines=lines+" "+x - } - + //val useDBText = "use "+database + ";" + var sqlString:String=HdfsUtil.getLines(hiveQL_path) + sqlString.split(";").foreach( s => { + println("Sql is " + s) + sql(s) }) + } def initialize(ctx: ProcessContext): Unit = { @@ -45,7 +39,7 @@ class PutHiveQL extends ConfigurableStop { } def setProperties(map : Map[String, Any]): Unit = { - hiveQL_path = MapUtil.get(map,"hiveQL_path").asInstanceOf[String] + hiveQL_path = MapUtil.get(map,"hiveQL_Path").asInstanceOf[String] database = MapUtil.get(map,"database").asInstanceOf[String] } diff --git a/piflow-core/src/main/scala/cn/piflow/util/HdfsUtil.scala b/piflow-core/src/main/scala/cn/piflow/util/HdfsUtil.scala index 93f3265..f6464dc 100644 --- a/piflow-core/src/main/scala/cn/piflow/util/HdfsUtil.scala +++ b/piflow-core/src/main/scala/cn/piflow/util/HdfsUtil.scala @@ -54,9 +54,9 @@ object HdfsUtil { line } - def getLines(file : String) : List[String] = { + def getLines(file : String) : String = { - var result = List[String]() + var result = "" var line : String = "" var inputStream : FSDataInputStream = null var bufferedReader : BufferedReader = null @@ -66,7 +66,7 @@ object HdfsUtil { bufferedReader = new BufferedReader(new InputStreamReader(inputStream)) line = bufferedReader.readLine(); while (line != null){ - result = line +: result + result = result + " " + line line = bufferedReader.readLine() }