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

add prefix option to meta #43

Merged
merged 1 commit into from Sep 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/scala/org/apache/spark/sql/TiContext.scala
Expand Up @@ -37,15 +37,16 @@ class TiContext (val session: SparkSession, addressList: List[String]) extends S
sqlContext.baseRelationToDataFrame(tiRelation)
}

def tidbMapDatabase(dbName: String): Unit =
def tidbMapDatabase(dbName: String, dbNameAsPrefix: Boolean = false): Unit =
meta.getDatabase(dbName).foreach {
db => {
meta.getTables(db).foreach {
table => {
val rel: TiDBRelation =
new TiDBRelation(new TiOptions(addressList, dbName, table.getName), meta)(sqlContext)
if (!sqlContext.sparkSession.catalog.tableExists(table.getName)) {
sqlContext.baseRelationToDataFrame(rel).createTempView(table.getName)
val tableName = if (dbNameAsPrefix) db.getName + "_" + table.getName else table.getName
sqlContext.baseRelationToDataFrame(rel).createTempView(tableName)
logInfo("Registered table " + table.getName)
}
}
Expand Down