defgetChannelTable(spark: SparkSession, date: String): String = { val db = "dim" var result = "channel_tbl"// set with default import spark.implicits._ spark.sql(s"show tables in ${db} like 'channel_tbl_*'") .map(_.getString(1)) .filter(tbl => { val sdf = newSimpleDateFormat("yyyyMMdd") val items = tbl.split("_") if (items.length == 4) { // channel_tbl_20210304_20210310 val start = sdf.parse(items(2)).getTime val end = sdf.parse(items(3)).getTime val time = sdf.parse(date).getTime if (time >= start && time <= end) { true } else { false } } else { false } }).collect().foreach(tbl => { result = s"${db}.${tbl}"// update if any match }) result }