Skip to content

Instantly share code, notes, and snippets.

@Gatsby-Lee
Last active August 21, 2022 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gatsby-Lee/8dd469ec0f29188c3e43961ecd3e963d to your computer and use it in GitHub Desktop.
Save Gatsby-Lee/8dd469ec0f29188c3e43961ecd3e963d to your computer and use it in GitHub Desktop.
-- Table schema with JSON output format
CREATE EXTERNAL TABLE `discover_cluster_tickets_dummy_json_v1`(
`cluster_id` string,
`created_date` timestamp
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE
LOCATION 's3://aws-athena/my_db/dummy_json_v1/';
-- INSERT stmt
INSERT INTO dummy_json_v1 (cluster_id, created_date) VALUES ('89f921dc', timestamp '2022-03-24 17:45:02.0');
-- CREATE JSON output format data with CTAS
CREATE TABLE my_db.dummy_json_v1
WITH (
format = 'JSON',
external_location = 's3://aws-athena/my_db/dummy_json_v1'
)
AS SELECT *
FROM my_db.dummy_orc_v1;
-- expected content in file
{"cluster_id":"89f921dc","created_date":"2022-03-24 17:45:02.0"}
{"cluster_id":"a420cac4","created_date":"2022-07-21 21:13:28.0"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment