I am trying to match a word from a table's columns by iterating a list which contains the column names.
columnMap
-> Map which contains column data in the form of: key->locations
and
value->period:int|name:String|uniform_period:String|database:String|amount:Double|period_num:Int
Out of these columns, I have a hive partition column: period
which is present in another List and in order to make sure that my partition column is present in the table columns, I tried using contains
as below.
val columnMap = Map[String, String]()
def partitionDataTypes(hiveTab:String, prtn_String_columns:String):String = {
val pcols = prtn_String_columns.split(",").toSeq
var pList = scala.collection.mutable.TreeSet[String]()
columnMap.foreach {
case (k, v) => if (columnMap.contains(hiveTab)) {
var cols = columnMap(hiveTab).split("\\|")
for (c <- cols) {
for (p <- pcols) {
if(c.contains(p)) pList ++ c
}
}
}
}
println("Partition Columns: " + pList.toString())
pList.toString()
}
If the input list: pcols
contains: period
, the contains function is resulting in the output values of: period, uniform_period & period_num
whereas I only have to get exact match "period".
How do I form a regex pattern to match the columnMap
data by matching each element of it which starts with element from pcols
and ends before :
as given in the loop above.