Streams
Streams
Streams
-- create a database
create database my_db
comment = 'this is my demo db';
-- as soon as you create the db, the context is changed and current db is set
select current_role(), current_database();
-- create a schema
create schema my_schema
comment = 'this is my demo schema under my_db';
show schemas;
-- as soon as you create the db, the context is changed and current db is set
select current_role(), current_database(), current_schema();
-- lets change the context using use sql statement (or via ... function from
worksheet)
use database my_db;
use schema my_schema;
select current_role(), current_database(), current_schema();
select get_ddl('table','my_table');
--
drop table if exists my_text_table;
create table my_text_table (
id int autoincrement,
v varchar,
v50 varchar(50),
c char,
c10 char(10),
s string,
s20 string(20),
t text,
t30 text(30)
);
// ====================================================================
-- Upper, Lower & Mixed case table
drop table my_case_table;
create table my_case_table (my_field string);
desc table my_case_table;
show tables like 'MY_C%';
create table MY_CASE_TABLE (my_field string);
create table my_CASE_TABLE (my_field string);
// ====================================================================
-- Object Identifier
create table "my table" (my_field string);
create table "My Table" ("my field" string);
create table "MY TABLE" ("my field" string, "My Field" string);
show tables;
desc table "my table";
desc table "MY TABLE" ;
// ====================================================================
-- Create table as select
create table my_ctas as select * from my_db.my_schema.my_table;
// =====================================================================
-- lets quickly understand the const
drop table if exists my_constaints_table;
create table my_constaints_table (
emp_pk string primary key,
fname string not null,
lname string not null,
flag string default 'active',
unique_code string unique
);
// =========================================================
list @my_stg;
/* sample data
100,22.2,33.33,123456789,987654321,12112
200,22.2,33.33,123456789,987654321,12112
300,22.2,33.33,123456789,987654321,12112
*/
//=======================================
-- Variant Data
create table json_weather_data (v variant);
desc table json_weather_data;
-- list wheather
list @nyc_weather;
-- select data
select * from json_weather_data limit 10;
-- create a view
create view json_weather_data_view as
select
v:time::timestamp as observation_time,
v:city.id::int as city_id,
v:city.name::string as city_name,
v:city.country::string as country,
v:city.coord.lat::float as city_lat,
v:city.coord.lon::float as city_lon,
v:clouds.all::int as clouds,
(v:main.temp::float)-273.15 as temp_avg,
(v:main.temp_min::float)-273.15 as temp_min,
(v:main.temp_max::float)-273.15 as temp_max,
v:weather[0].main::string as weather,
v:weather[0].description::string as weather_desc,
v:weather[0].icon::string as weather_icon,
v:wind.deg::float as wind_dir,
v:wind.speed::float as wind_speed
from json_weather_data
where city_id = 5128638;
)
with location=@nyc_weather
auto_refresh = false
file_format = (format_name = file_format)
;
// =======================================
-- Temp & Transitent table