cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

External Table from volume

smpa01
Contributor

@szymon_dybczak 

I am experimenting to see if there is a way for me to create an external table from files written into unity catalog volume. I tried the following but it did not work.

# COMMAND ----------
# DBTITLE 1, Daily Fetch and Write 

# sample daily fetch from API call and write to <catlog>.<schema>.<volume>.<folder>
data = [
    {
        'id':1,
        'name':'John Doe',
        'age':20
    },
        {
        'id':2,
        'name':'Jane Doe',
        'age':30
    }
]
df = spark.createDataFrame(data)

# write files to volume <Catalog>- workspace; <schema> db_bronze; <volume> volume; <folder> test_01 to store daily fetch from API
df.write\
    .format('delta')\
    .mode('append')\
    .option('mergeSchema','true')\
    .clusterBy('id')\
    .save('/Volumes/workspace/db_bronze/volume/test_01')
	

# COMMAND ----------
# DBTITLE 2, Test Read from Volume

# Reading successful


location = 'dbfs:/Volumes/workspace/db_bronze/volume/test_01/'

df = spark.read.format('delta').load(location)

display(df)


# COMMAND ----------
# DBTITLE 3, Create External Table

%sql
/*not successful*/
CREATE TABLE IF NOT EXISTS  workspace.db_bronze.people(id long,name string,age long)
using DELTA
location 'dbfs:/Volumes/workspace/db_bronze/volume/test_01/'

I am not sure what am I doing wrong here.

1 ACCEPTED SOLUTION

Accepted Solutions

Pat
Esteemed Contributor

Hi @smpa01 ,

You cannot create external table on the data in volume:

Pat_0-1752743933746.png

see link to documentation: https://docs.databricks.com/gcp/en/volumes

View solution in original post

2 REPLIES 2

szymon_dybczak
Esteemed Contributor III

Hi @smpa01 ,

Could you also attach what error did you get? And could you try removing dbfs from following part?

/*not successful*/
CREATE TABLE IF NOT EXISTS  workspace.db_bronze.people(id long,name string,age long)
using DELTA
location '/Volumes/workspace/db_bronze/volume/test_01/'

Pat
Esteemed Contributor

Hi @smpa01 ,

You cannot create external table on the data in volume:

Pat_0-1752743933746.png

see link to documentation: https://docs.databricks.com/gcp/en/volumes