Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add if not exists again
  • Loading branch information
baishuo committed Mar 17, 2015
commit 6a756bf88587eb6c317778beb23435d65eb46ba6
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private[hive] object HiveShim {
def getStatsSetupConstRawDataSize = StatsSetupConst.RAW_DATA_SIZE

def createDefaultDBIfNeeded(context: HiveContext) = {
context.runSqlHive("CREATE DATABASE default")
context.runSqlHive("CREATE DATABASE IF NOT EXISTS default")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add it in Shim12?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we do not need to modify Shim12, Since there is not the same function in Shim12

Copy link
Contributor

Choose a reason for hiding this comment

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

LTGM since it's much safer. But I am curious how did it pass the unit test previously. Seems the database default will not be created while initializing, unless we create it explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit tricky to explain. When initializing a TestHiveContext, the following things happen:

  1. HiveContext.hiveconf is initialized (notice that the metastore and warehouse paths point to the whatever configured in hive-site.xml or the default locations)
  2. HiveContext.sessionState is initialized
  3. TestHiveContext.configure() is called, metastore and warehouse paths now point to temporary directories used for testing purposes, no default database is defined there.
  4. HiveShim.createDefaultDbIfNeeded() is called to create the default database in the temproary directories.

As Michael commented, the createDefaultDbIfNeeded method is more like a hack to fix the initialization disorder. And that's why I opened baishuo#2 against this PR branch. In that PR, the root cause of this initialization disorder is fixed.

context.runSqlHive("USE default")
}

Expand Down