cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a table like in SQL with Spark

Adrien
New Contributor

Hi !

I'm working on a project at my company on Databricks using Scala and Spark. I'm new to Spark and Databricks and so I would like to know how to create a table on specific location (on the Delta Lake of my company). In SQL + some Delta features, I would have done it like so :

CREATE OR REPLACE TABLE delta.`mnt/peth/to/MyTable` (
    id SERIAL    PRIMARY KEY,
    m1 TIMESTAMP NOT NULL,
    m2 TIMESTAMP NOT NULL
) USING DELTA

However, it seems that PRIMARY KEY as well as SERIAL is not recognize by Spark. So how can I make it understand I want this column to be in auto-increment and signed integer so I can simply do this to add new values :

INSERT INTO MyTable VALUES (m1Value, m2Value)

Thank you

PS : I tried to use dataframes but when making unions to add a new row, Spark decide to only keep the last row of the table + the new row, so I want to skip dataframes if possible.

PS2 : MyTable will not be used simultaneously by many process. It will be only successive calls

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @ Stime! My name is Kaniz, and I'm the technical moderator here. Great to meet you, and thanks for your question! Let's see if your peers in the community have an answer to your question first. Or else I will get back to you soon. Thanks.

jose_gonzalez
Moderator
Moderator

Hi @Adrien MERAT​ ,

I would like to share the following documentation that will provide examples on how to create Delta tables:

  • Create Delta table link
  • Delta data types link
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.