Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support path parameterization for file data #113

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ final case class Argument(config: String = "application.conf",
hive: Boolean = false,
directly: Boolean = false,
dry: Boolean = false,
reload: String = "")
reload: String = "",
file: Boolean = false,
path: String = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a great work, thanks!
maybe we should use more understandable variable name,how about change file to variablepath to param?

Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,16 @@ object Configs {
* @param configPath
* @return
*/
def parse(configPath: String): Configs = {
def parse(configPath: String, file:Boolean=false, path:String = ""): Configs = {
var config: Config = null
var paths: Map[String,String] = null
if (file) {
if (paths.isEmpty) throw new IllegalArgumentException(s"-p must to set ")
paths = path.split(",").map(path => {
val kv = path.split("=")
(kv(0), kv(1))
}).toMap
}
if (configPath.startsWith("hdfs://")) {
val hadoopConfig: Configuration = new Configuration()
val fs: FileSystem = org.apache.hadoop.fs.FileSystem.get(hadoopConfig)
Expand Down Expand Up @@ -391,7 +399,7 @@ object Configs {
}

val sourceCategory = toSourceCategory(tagConfig.getString("type.source"))
val sourceConfig = dataSourceConfig(sourceCategory, tagConfig, nebulaConfig)
val sourceConfig = dataSourceConfig(sourceCategory, tagConfig, nebulaConfig,file,paths)
LOG.info(s"Source Config ${sourceConfig}")
hasKafka = sourceCategory == SourceCategory.KAFKA

Expand Down Expand Up @@ -455,7 +463,7 @@ object Configs {
edgeConfig.hasPath("longitude")

val sourceCategory = toSourceCategory(edgeConfig.getString("type.source"))
val sourceConfig = dataSourceConfig(sourceCategory, edgeConfig, nebulaConfig)
val sourceConfig = dataSourceConfig(sourceCategory, edgeConfig, nebulaConfig,file,paths)
LOG.info(s"Source Config ${sourceConfig}")
hasKafka = sourceCategory == SourceCategory.KAFKA

Expand Down Expand Up @@ -614,14 +622,19 @@ object Configs {
*/
private[this] def dataSourceConfig(category: SourceCategory.Value,
config: Config,
nebulaConfig: Config): DataSourceConfigEntry = {
nebulaConfig: Config,
file:Boolean,
paths: Map[String,String]): DataSourceConfigEntry = {
category match {
case SourceCategory.PARQUET =>
FileBaseSourceConfigEntry(SourceCategory.PARQUET, config.getString("path"))
if (file) FileBaseSourceConfigEntry(SourceCategory.PARQUET, paths(config.getString("path")))
else FileBaseSourceConfigEntry(SourceCategory.PARQUET, config.getString("path"))
case SourceCategory.ORC =>
FileBaseSourceConfigEntry(SourceCategory.ORC, config.getString("path"))
if (file) FileBaseSourceConfigEntry(SourceCategory.ORC, paths(config.getString("path")))
else FileBaseSourceConfigEntry(SourceCategory.ORC, config.getString("path"))
case SourceCategory.JSON =>
FileBaseSourceConfigEntry(SourceCategory.JSON, config.getString("path"))
if (file) FileBaseSourceConfigEntry(SourceCategory.JSON, paths(config.getString("path")))
else FileBaseSourceConfigEntry(SourceCategory.JSON, config.getString("path"))
case SourceCategory.CSV =>
val separator =
if (config.hasPath("separator"))
Expand All @@ -632,10 +645,16 @@ object Configs {
config.getBoolean("header")
else
false
FileBaseSourceConfigEntry(SourceCategory.CSV,
config.getString("path"),
if (file)
FileBaseSourceConfigEntry(SourceCategory.CSV,
paths(config.getString("path")),
Some(separator),
Some(header))
else
FileBaseSourceConfigEntry(SourceCategory.CSV,
config.getString("path"),
Some(separator),
Some(header))
case SourceCategory.HIVE =>
HiveSourceConfigEntry(SourceCategory.HIVE, config.getString("exec"))
case SourceCategory.NEO4J =>
Expand Down Expand Up @@ -966,6 +985,16 @@ object Configs {
.valueName("<path>")
.action((x, c) => c.copy(reload = x))
.text("reload path")

opt[Unit]('f', "file")
.action((_, c) => c.copy(file = true))
.text("enable file param")

opt[String]('p', "paths")
.valueName("<param>")
.action((x, c) => c.copy(path = x))
.text("file param path")

}
parser.parse(args, Argument())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object Exchange {
sys.exit(-1)
}

val configs = Configs.parse(c.config)
val configs = Configs.parse(c.config,c.file,c.path)
LOG.info(s"Config ${configs}")

val session = SparkSession
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object Exchange {
sys.exit(-1)
}

val configs = Configs.parse(c.config)
val configs = Configs.parse(c.config,c.file,c.path)
LOG.info(s"Config ${configs}")

val session = SparkSession
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object Exchange {
sys.exit(-1)
}

val configs = Configs.parse(c.config)
val configs = Configs.parse(c.config,c.file,c.path)
LOG.info(s"Config ${configs}")

val session = SparkSession
Expand Down