Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
aebdfc6
[SPARK-19667][SQL]create table with hiveenabled in default database u…
windpiger Feb 20, 2017
825c0ad
rename a conf name
windpiger Feb 20, 2017
a2c9168
fix test faile
windpiger Feb 21, 2017
bacd528
process default database location when create/get database from metas…
windpiger Feb 22, 2017
3f6e061
remove an redundant line
windpiger Feb 22, 2017
96dcc7d
fix empty string location of database
windpiger Feb 22, 2017
f329387
modify the test case
windpiger Feb 22, 2017
83dba73
Merge branch 'master' into defaultDBPathInHive
windpiger Feb 22, 2017
58a0020
fix test failed
windpiger Feb 22, 2017
1dce2d7
add log to find out why jenkins failed
windpiger Feb 22, 2017
12f81d3
add scalastyle:off for println
windpiger Feb 22, 2017
56e83d5
fix test faile
windpiger Feb 22, 2017
901bb1c
make warehouse path qualified for default database
windpiger Feb 23, 2017
99d9746
remove a string s
windpiger Feb 23, 2017
db555e3
modify a comment
windpiger Feb 23, 2017
d327994
fix test failed
windpiger Feb 23, 2017
73c8802
move to sessioncatalog
windpiger Feb 23, 2017
747b31a
remove import
windpiger Feb 23, 2017
8f8063f
remove an import
windpiger Feb 23, 2017
4dc11c1
modify some codestyle and some comment
windpiger Feb 24, 2017
9c0773b
Merge branch 'defaultDBPathInHive' of github.com:windpiger/spark into…
windpiger Feb 24, 2017
80b8133
mv defaultdb path logic to ExternalCatalog
windpiger Feb 27, 2017
41ea115
modify a comment
windpiger Feb 27, 2017
13245e4
modify a comment
windpiger Feb 27, 2017
096ae63
add final def
windpiger Mar 1, 2017
badd61b
modify some code
windpiger Mar 2, 2017
35d2b59
add lazy flag
windpiger Mar 2, 2017
e3a467e
modify test case
windpiger Mar 3, 2017
ae9938a
modify test case
windpiger Mar 3, 2017
7739ccd
mv getdatabase
windpiger Mar 3, 2017
f93f5d3
merge with master
windpiger Mar 8, 2017
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
Next Next commit
[SPARK-19667][SQL]create table with hiveenabled in default database u…
…se warehouse path instead of the location of default database
  • Loading branch information
windpiger committed Feb 20, 2017
commit aebdfc6863a0a049b1062218a882a5ae486558ad
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ object SQLConf {
.stringConf
.createWithDefault(TimeZone.getDefault().getID())

// for test
val HIVE_CREATETABLE_DEFAULTDB_USEWAREHOUSE_PATH =
buildConf("spark.hive.createTable.defaultDB.location.useWarehousePath")
.doc("Enables test case to use warehouse path instead of db location when " +
"create table in default database.")
.booleanConf
.createWithDefault(false)

object Deprecated {
val MAPRED_REDUCE_TASKS = "mapred.reduce.tasks"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap
import org.apache.spark.sql.execution.command.DDLUtils
import org.apache.spark.sql.execution.datasources.PartitioningUtils
import org.apache.spark.sql.hive.client.HiveClient
import org.apache.spark.sql.internal.HiveSerDe
import org.apache.spark.sql.internal.{HiveSerDe, SQLConf}
import org.apache.spark.sql.internal.StaticSQLConf._
import org.apache.spark.sql.types.{DataType, StructType}

Expand Down Expand Up @@ -407,8 +407,14 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
properties
}

// if the database is default, the value of WAREHOUSE_PATH in conf returned
private def defaultTablePath(tableIdent: TableIdentifier): String = {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about we put this logic in ExternalCatalog? e.g. ExternalCatalog.getDatabase will check the default database and then call getDatabaseInternal which need to be implemented by subclasses.

Copy link
Contributor

Choose a reason for hiding this comment

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

or let's just move this defaultTablePath function to ExternalCatalog, and we use it in InMemoryCatalog and HiveExternalCatalog

Copy link
Contributor Author

@windpiger windpiger Feb 25, 2017

Choose a reason for hiding this comment

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

I'd like the first one, defaultTablePath in SessionCatalog has been used in CreateDataSourceAsSelectCommand, I think it is useful to keep it in SessionCatalog, maybe later in another place we want to use it.
If it is ok, I will change the code using the first one you proposed.

val dbLocation = getDatabase(tableIdent.database.get).locationUri
val dbLocation = if (tableIdent.database.get == SessionCatalog.DEFAULT_DATABASE
|| conf.get(SQLConf.HIVE_CREATETABLE_DEFAULTDB_USEWAREHOUSE_PATH)) {
conf.get(WAREHOUSE_PATH)
} else {
getDatabase(tableIdent.database.get).locationUri
}
new Path(new Path(dbLocation), tableIdent.table).toString
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,4 +1587,49 @@ class HiveDDLSuite
}
}
}

test("create table with default database use warehouse path instead of database location") {
withTable("t") {
withTempDir { dir =>
spark.sparkContext.conf
.set(SQLConf.HIVE_CREATETABLE_DEFAULTDB_USEWAREHOUSE_PATH.key, "true")

spark.sql(s"CREATE DATABASE default_test LOCATION '$dir'" )
val db = spark.sessionState.catalog.getDatabaseMetadata("default_test")
assert(db.locationUri.stripSuffix("/") == s"file:${dir.getAbsolutePath.stripSuffix("/")}")
spark.sql("USE default_test")
val sparkWarehouseTablePath = s"file:${spark.sharedState.warehousePath.stripSuffix("/")}/t"

spark.sql("CREATE TABLE t(a string)")
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
assert(table.location.stripSuffix("/") == sparkWarehouseTablePath )

// clear
spark.sparkContext.conf
.remove(SQLConf.HIVE_CREATETABLE_DEFAULTDB_USEWAREHOUSE_PATH.key)
spark.sql("DROP TABLE t")
spark.sql("DROP DATABASE default_test")
spark.sql("USE DEFAULT")
}

withTempDir { dir =>
spark.sql(s"CREATE DATABASE test_not_default LOCATION '$dir'" )
val db = spark.sessionState.catalog.getDatabaseMetadata("test_not_default")
assert(db.locationUri.stripSuffix("/") == s"file:${dir.getAbsolutePath.stripSuffix("/")}")
spark.sql("USE test_not_default")
val sparkWarehouseTablePath = s"file:${spark.sharedState.warehousePath.stripSuffix("/")}/t"

spark.sql("CREATE TABLE t(a string)")
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
assert(table.location.stripSuffix("/") == s"${db.locationUri.stripSuffix("/")}/t" )

// clear
spark.sparkContext.conf
.remove(SQLConf.HIVE_CREATETABLE_DEFAULTDB_USEWAREHOUSE_PATH.key)
spark.sql("DROP TABLE t")
spark.sql("DROP DATABASE test_not_default")
spark.sql("USE DEFAULT")
}
}
}
}