-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkinesis-table.py
28 lines (24 loc) · 929 Bytes
/
kinesis-table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pyspark.sql.types import LongType, DateType, StructType, StructField, StringType
from pyspark.sql.functions import current_date
import datetime
CatalogDatabaseTable = "demo.dev.my_kinesis_table"
# Create table
schema = StructType([
StructField("timestamp", LongType(), True),
StructField("datedatapart", DateType(), True),
StructField("tenantid", StringType(), True),
StructField("clientid", StringType(), True),
StructField("resource", StringType(), True)
])
df = spark.createDataFrame([], schema)
df.writeTo(CatalogDatabaseTable).create()
# Write table data
schema = spark.table(CatalogDatabaseTable).schema
data = [
(10000000000548, datetime.date(1111, 1, 1), "test", "test", "/test"),
(10000000000548, datetime.date(2222, 2, 2), "test", "test", "/test")
]
df = spark.createDataFrame(data, schema)
df.writeTo(CatalogDatabaseTable).append()
# Read table
df = spark.table(CatalogDatabaseTable).show()