Delta: Support for registering Delta tables in the HiveMetastore

Created on 8 Jul 2019  Â·  25Comments  Â·  Source: delta-io/delta

While delta tracks its own metadata in the transaction log, the Hive Metastore is still important as it enables users to find tables without knowing the path to the data.

This ticket tracks adding the ability to run CREATE TABLE to create a new metastore table, or to register an existing table in the metastore.

enhancement

Most helpful comment

@marmbrus @tdas

    spark.range(10).write.format("delta").save("/tmp/events")
    spark.sql("create table events using delta location '/tmp/events'")
    spark.sql("select * from events").show(100)

Registering an existing table in the metastore seems work already, so this feature is mainly for creating new table like https://github.com/delta-io/delta/issues/177?

All 25 comments

Is there any chance that this would be part of the 0.4.0 milestone?

Hard to say. It all depends on the timing of the Spark 3.0.0 release. We are working with the Spark community to add the necessary Datasource V2 APIs that would allow us to plug into all the DDLs like CREATE TABLE, ALTER TABLE, etc. and make them work with Hive metastore + Delta combined setup. Those new APIs are targetted for Spark 3.0.0.

@marmbrus @tdas

    spark.range(10).write.format("delta").save("/tmp/events")
    spark.sql("create table events using delta location '/tmp/events'")
    spark.sql("select * from events").show(100)

Registering an existing table in the metastore seems work already, so this feature is mainly for creating new table like https://github.com/delta-io/delta/issues/177?

@marmbrus @tdas

    spark.range(10).write.format("delta").save("/tmp/events")
    spark.sql("create table events using delta location '/tmp/events'")
    spark.sql("select * from events").show(100)

Registering an existing table in the metastore seems work already, so this feature is mainly for creating new table like #177?

@yucai I had exactly the exception as it is appears in #177 when I run your code

Is there any workaround to register Delta table in Hive metastore using Spark API?

@dgreenshtein it works for me perfectly. I run them like below:

branch-2.4 git:(branch-2.4) ✗ ./bin/spark-shell --packages io.delta:delta-core_2.11:0.3.0

@dgreenshtein it works for me perfectly. I run them like below:

branch-2.4 git:(branch-2.4) ✗ ./bin/spark-shell --packages io.delta:delta-core_2.11:0.3.0

hm, the only difference is delta.io version. I am running io.delta:delta-core_2.11:0.4.0.

Did not work with 0.3.0 as well.

@dgreenshtein
In fact, when we use the "create table xxx" sql statement, prompt as follows

WARN hive.HiveExternalCatalog: Couldn't find corresponding Hive SerDe for data source provider delta. Persisting data source table `default`.`events` into Hive metastore in Spark SQL specific format, which is NOT compatible with Hive.

Just created metastore_db locally, can't access Hive metastore

Any news on this ?

Also trying to register my delta table to hive metastore without success.

I'm running Spark 2.4.4 as follows :

./spark-shell --packages io.delta:delta-core_2.11:0.5.0 --conf spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension

And trying to run

spark.range(10).write.format("delta").save("/tmp/events")
spark.sql("create table events using delta location '/tmp/events'")
spark.sql("select * from events").show(100)

I'm having the following error :
hive.HiveExternalCatalog: Couldn't find corresponding Hive SerDe for data source provider delta.

Any idea ?

No updates; we can't support this until Spark 3.0 is released. It's on our future roadmap to support once 3.0 comes out.

Is there any metastore that is currently supported with the 0.5.0 version ? Does Glue or any other work ? Is there a standalone metastore for delta lake ? I can't seem to find it in the documentation and I need to register my tables to perform the auto compaction optimizations.

Thanks

If you're running on Databricks (which I assume you mean by running auto-compaction optimizations, which are only available there), Hive and Glue metastores are both supported. See https://docs.databricks.com/delta/delta-batch.html#create-a-table.

This project is for discussion around open-source Delta Lake. If you have any questions about Databricks, feel free to open a support ticket or ask on Slack.

I'm using the open-source version. Do I have any metastore available ? Is there a list of features only available on the databricks distribution ? Thanks

Delta Lake on Databricks has some performance optimizations as a result of being part of the Databricks Runtime; we're aiming for full API compatibility in OSS Delta Lake (though for some things like metastore support that requires changes only coming in Spark 3.0). Auto compaction is only available in Databricks; if you're talking about the Hive-ACID compaction, that won't work with Delta Lake. You can implement your own compaction using something like https://docs.delta.io/latest/best-practices.html#compact-files.

If you have any further questions, please create a new issue.

We just migrated to Databricks Delta from parquet using Hive metastore. So far everything seems to
work fine, when I try to print out the location of the new Delta table using DESCRIBE EXTENDED my_table the location is correct although it is different than the one found in the hiveMetastore database. When I access the hiveMetastore database I can successfully identify the target table (also provider is correctly set to Delta). To retrieve the previous information I am executing a join between sds, dbs, tbls and table_params tables from hiveMetastore db, filtering by table name as shown next:

val sdsDF = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.SDS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val tblsDf = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.TBLS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val dbsDf = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.DBS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val paramsDf = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.TABLE_PARAMS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val resDf = sdsDF.join(tblsDf, "SD_ID")
     .join(dbsDf, "DB_ID") 
     .join(paramsDf, "TBL_ID") 
     .where('TBL_NAME.rlike("mytable"))
     .select($"TBL_NAME", $"TBL_TYPE", $"NAME".as("DB_NAME"), $"DB_LOCATION_URI", $"LOCATION".as("TABLE_LOCATION"), $"PARAM_KEY", $"PARAM_VALUE")

All the previous are executed from a databricks notebook.

My question is why I am getting two different locations even if the table name is the same? Where is the correct location for the Delta tables stored if not on hiveMetastore db?

What are the two different locations? can you show the output of resDF?

I can't show the actual values although they are completely different S3 paths @tdas none of them is somehow related to the other. i.e root of the other etc. Is there anything I should try? Where should the Delta table location be stored in this case?

Neither of them matches the actual one? Either way, this issue is not related to the root issue of metastore support, so maybe we should make a different issue for this. Though I doubt we can do anything without taking a deeper look. It might better to actually contact databricks support so that we can look at what is going on.

One path should look like dbfs:/user/hive/warehouse/XXXXXX-__PLACEHOLDER__. I don't know why Spark needs to write this placeholder path, maybe some codes require something to be there. The other path should be the real table location.

Just a status update on the support for defining Delta-format tables in Hive Metastore. We are going to add support for defining tables and all the associated DDL commands (CREATE, ALTER, DROP, etc.) in Delta Lake 0.7.0 when we will add support for Apache Spark 3.0. Delta Lake 0.7.0 is expected to come out roughly in June/July, whenever the Apache Spark community votes and decides to release 3.0.

My excuses for the late reply, I have some updates regarding this one. I tried to execute the next code:

val sdsDF = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.SDS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val tblsDf = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.TBLS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val dbsDf = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.DBS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val paramsDf = spark.read
  .format("jdbc")
  .option("url", activeConnection.url)
  .option("dbtable", "hiveMetastore.TABLE_PARAMS")
  .option("user", activeConnection.user)
  .option("password", activeConnection.pwd)
  .load()

val resDf = sdsDF.join(tblsDf, "SD_ID")
     .join(dbsDf, "DB_ID") 
     .join(paramsDf, "TBL_ID") 
     .where('TBL_NAME === "my_table" && 'NAME === "db_production")
     .select($"TBL_NAME", $"TBL_TYPE", $"NAME".as("DB_NAME"), $"DB_LOCATION_URI", $"LOCATION".as("TABLE_LOCATION"), $"PARAM_KEY", $"PARAM_VALUE")

Which is similar to the previous code with the difference that in addition I join with hiveMetastore.TABLE_PARAMS. Here is how the output looks like:

|TBL_NAME|TBL_TYPE      |DB_NAME      |DB_LOCATION        |TABLE_LOCATION                              |PARAM_KEY                        |PARAM_VALUE                  |
+--------+--------------+-------------+-------------------+--------------------------------------------+---------------------------------+-----------------------------+
|my_table|EXTERNAL_TABLE|db_production|s3://invalid_db_uri|s3://invalid_db_uri/my_table-__PLACEHOLDER__|EXTERNAL                         |TRUE                         |
|my_table|EXTERNAL_TABLE|db_production|s3://invalid_db_uri|s3://invalid_db_uri/my_table-__PLACEHOLDER__|spark.sql.create.version         |2.4.3                        |
|my_table|EXTERNAL_TABLE|db_production|s3://invalid_db_uri|s3://invalid_db_uri/my_table-__PLACEHOLDER__|spark.sql.sources.provider       |DELTA                        |
|my_table|EXTERNAL_TABLE|db_production|s3://invalid_db_uri|s3://invalid_db_uri/my_table-__PLACEHOLDER__|spark.sql.sources.schema.numParts|1                            |
|my_table|EXTERNAL_TABLE|db_production|s3://invalid_db_uri|s3://invalid_db_uri/my_table-__PLACEHOLDER__|spark.sql.sources.schema.part.0  |{"type":"struct","fields":[]}|
|my_table|EXTERNAL_TABLE|db_production|s3://invalid_db_uri|s3://invalid_db_uri/my_table-__PLACEHOLDER__|transient_lastDdlTime            |1582204169                   |
+--------+--------------+-------------+-------------------+--------------------------------------------+---------------------------------+-----------------------------+

As you can see DB_LOCATION and TABLE_LOCATION have invalid values and they don't correspond to the actual S3 path. @zsxwing as you can see the path is still S3 not dbfs. @tdas when I do DESCRIBE EXTENDED my_table the path is the correct Delta path. Actually, this is one of my question why I don't see the same/valid path in the hiveMetastore?

Thank you both

Is there any tentative timeline to have the functionality to creat the DeltaTable API for manged tables?

We are hoping to make a 0.7.0-preview release on Spark 3.0/RCx in the next couple of weeks. Most of the code changes for metastore support have merged into master. Hence, I am closing this ticket.

Was this issue closed on the hope of some code getting integrated into a Spark 3.0 preview release and not from a verified and tested publicly available general release?

If that really poor release management!!!

Please specify exactly what release combinations have been proven to work.

This has been released in Delta 0.7.0 on Spark 3.0. Please see the attached milestone and the corresponding release notes in https://github.com/delta-io/delta/releases

Was this page helpful?
0 / 5 - 0 ratings