Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CREATE EXTERNAL TABLE statement #1394

Closed
Tracked by #3
penghuo opened this issue Mar 3, 2023 · 1 comment
Closed
Tracked by #3

Add CREATE EXTERNAL TABLE statement #1394

penghuo opened this issue Mar 3, 2023 · 1 comment

Comments

@penghuo
Copy link
Collaborator

penghuo commented Mar 3, 2023

No description provided.

@penghuo penghuo changed the title Grammer, CREATE EXTERNAL TABLE. Add CREATE EXTERNAL TABLE statement Mar 3, 2023
@penghuo
Copy link
Collaborator Author

penghuo commented Mar 3, 2023

CREATE TABLE IF NOT EXISTS p001 (name STRING, age INT) 
USING PARQUET
LOCATION "/Users/penghuo/release/deltalake/parquet/p001";

INSERT INTO default.p001 VALUES ('a', 1), ('b', 2);
INSERT INTO default.p001 VALUES ('c', 3), ('d', 4);
  • detect new parquet files in dir
import org.apache.spark.sql.{DataFrame, SparkSession}
import org.apache.spark.sql.streaming._
import org.apache.spark.sql.types._
import org.apache.spark.sql.functions.input_file_name

val schema = new StructType().add("name", StringType).add("age", IntegerType)
val streamDF = spark.readStream.schema(schema).format("parquet").option("path", "/Users/penghuo/release/deltalake/parquet/p001").load()
val query = streamDF.select(input_file_name()).writeStream.format("console").start()
  • create external table
CREATE EXTERNAL TABLE IF NOT EXISTS default.t001
(name STRING, age INT)
USING DELTA
LOCATION "/Users/penghuo/release/deltalake/parquet/p001"
TBLPROPERTIES ('auto_refresh'='true');
  • add more data to parquet table
INSERT INTO default.p001 VALUES ('e', 5), ('f', 6);
INSERT INTO default.p001 VALUES ('g', 7);
  • check the result
    • the result should be reflected in t001
select * from t001 order by age;

a    1
b    2
c    3
d    4
e    5
f    6
g    7
* the delta_log should has new log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant