├── README.md ├── streamlit └── duckdb_minimal │ ├── requirements.txt │ └── streamlit_app.py ├── tweeting └── wordle_vaccines.sql ├── stream_and_tasks ├── prove_parallelism.sql └── minimal.sql ├── pivots └── readme.md ├── open_source_boards └── board_tenure.sql └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # snowflake_snippets -------------------------------------------------------------------------------- /streamlit/duckdb_minimal/requirements.txt: -------------------------------------------------------------------------------- 1 | duckdb 2 | google-cloud-storage 3 | -------------------------------------------------------------------------------- /streamlit/duckdb_minimal/streamlit_app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import duckdb 3 | 4 | from google.oauth2 import service_account 5 | from google.cloud import storage 6 | 7 | credentials = service_account.Credentials.from_service_account_info( 8 | st.secrets["gcp_service_account"] 9 | ) 10 | client = storage.Client(credentials=credentials) 11 | 12 | bucket = "fhoffa-lit" 13 | 14 | @st.experimental_memo(ttl=600) 15 | def read_file(bucket_name, file_path): 16 | bucket = client.bucket(bucket_name) 17 | return bucket.blob(file_path).download_as_string().decode("utf-8") 18 | 19 | "These are the contents of the CSV file read from GCS:" 20 | content = read_file(bucket, "myfile.csv") 21 | st.code(content) 22 | 23 | 24 | @st.experimental_memo(ttl=60000) 25 | def download_to_local_file(bucket_name, file_path, destination): 26 | bucket = client.bucket(bucket_name) 27 | return bucket.blob(file_path).download_to_filename(destination) 28 | 29 | download_to_local_file(bucket, "out/parquet__0_0_0.snappy.parquet", "temp.parquet") 30 | con = duckdb.connect(database=':memory:') 31 | 32 | "These are the contents of the Parquet file parsed with DuckDB:" 33 | df = con.execute("SELECT * FROM read_parquet('temp.parquet')").df() 34 | df 35 | 36 | "More on https://medium.com/@hoffa/magic-data-apps-with-snowflake-streamlit-and-duckdb-c0dfc0d1fbe2" 37 | -------------------------------------------------------------------------------- /tweeting/wordle_vaccines.sql: -------------------------------------------------------------------------------- 1 | with timeseries as ( 2 | select month, iso3166_1 3 | , coalesce(pfv 4 | , -- average prev and next when missing 5 | (lag(pfv) over(partition by iso3166_1 order by month) 6 | + lead(pfv) over(partition by iso3166_1 order by month)/2) 7 | ) percent_full 8 | from ( 9 | select date_trunc(month, date) month, iso3166_1, country_region 10 | , max(people_fully_vaccinated_per_hundred) pfv 11 | , max(total_vaccinations) tv 12 | from starschema_covid19.public.owid_vaccinations 13 | where iso3166_1 in ('JP', 'VN', 'US', 'BR', 'GB') 14 | and date > '2021-06-01' 15 | group by 1, 2, 3 16 | ) 17 | ), emoji as ( 18 | select $1 iso, $2 emoji 19 | from values('JP', '🇯🇵'), ('GB', '🇬🇧'), ('BR', '🇧🇷'), ('VN', '🇻🇳'), ('US', '🇺🇸'), ('IN', '🇮🇳') 20 | ), timeseries_emoji as ( 21 | select month, emoji 22 | , case 23 | when percent_full < 50 then '⬜' 24 | when percent_full < 68 then '🟨' 25 | else '🟩' 26 | end percent_full 27 | from timeseries 28 | join emoji 29 | on iso3166_1=iso 30 | ) 31 | 32 | select listagg($2, '\n') 33 | from ( 34 | select null::date, listagg(distinct emoji) within group (order by emoji) 35 | from timeseries_emoji 36 | union all ( 37 | select month, listagg(percent_full) within group (order by emoji) 38 | from timeseries_emoji 39 | group by 1 40 | order by month 41 | ) 42 | ) 43 | -------------------------------------------------------------------------------- /stream_and_tasks/prove_parallelism.sql: -------------------------------------------------------------------------------- 1 | -- This will create two parallel child queries that take 10 seconds to execute. 2 | -- If they are executed in parallel, then they will insert values at the same time. 3 | -- Event is triggered by inserting a value in a stream that is checked every minute. 4 | 5 | -- See https://stackoverflow.com/a/70100477/132438 6 | 7 | use role accountadmin; 8 | grant execute task on account to role sysadmin; 9 | use role sysadmin; 10 | 11 | -- stream so this task executes every minute, but only if there's new data 12 | create table just_timestamps_stream_table_with_count(value varchar); 13 | create stream just_timestamps_stream_count on table just_timestamps_stream_table_with_count; 14 | 15 | -- https://docs.snowflake.com/en/user-guide/tasks-intro.html 16 | create or replace task mytask_minute_parallel 17 | warehouse = test_small 18 | schedule = '1 MINUTE' 19 | when SYSTEM$STREAM_HAS_DATA('just_timestamps_stream_count') 20 | as 21 | -- consume stream so tasks doesn't execute again 22 | delete from just_timestamps_stream_table_with_count; 23 | 24 | -- our goal is to insert new timestamps here 25 | create or replace table just_timestamps(ts timestamp, note varchar); 26 | 27 | create or replace task mytask_minute_child1_parallel 28 | warehouse = test_small 29 | after mytask_minute_parallel 30 | as 31 | insert into just_timestamps 32 | select current_timestamp, 'child1 ' || count(seq4()) from table(generator(timelimit => 10)) v; 33 | 34 | create or replace task mytask_minute_child2_parallel 35 | warehouse = test_small 36 | after mytask_minute_parallel 37 | as 38 | insert into just_timestamps 39 | select current_timestamp, 'child2 ' || count(seq4()) from table(generator(timelimit => 10)) v; 40 | 41 | alter task mytask_minute_child2_parallel resume; 42 | alter task mytask_minute_child1_parallel resume; 43 | alter task mytask_minute_parallel resume; 44 | 45 | -- trigger a new run with new data in the stream 46 | insert into just_timestamps_stream_table_with_count values('trigger'); 47 | 48 | -- it works! 49 | select current_timestamp(), state, name, scheduled_time, error_message, * 50 | from table(information_schema.task_history()) 51 | limit 5; 52 | 53 | -- data has been added here 54 | select * 55 | from just_timestamps 56 | order by ts desc; 57 | -- if everything worked in parallel, both child tasks took 10 seconds, executed in parallel, and inserted at the same time 58 | 59 | 60 | -- clean up? 61 | show tasks; 62 | alter task mytask_minute_parallel suspend; 63 | drop task mytask_minute_parallel; 64 | drop task mytask_minute_child1_parallel; 65 | drop task mytask_minute_child2_parallel; 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /stream_and_tasks/minimal.sql: -------------------------------------------------------------------------------- 1 | -- Referenced from: 2 | -- https://stackoverflow.com/questions/59837417/is-there-a-way-to-force-run-a-snowflakes-task-now-before-the-next-scheduled-sl/65711613#65711613 3 | -- https://stackoverflow.com/questions/65710176/snowflake-schedule-a-script-sql-with-multiple-instructions-insert-delete-c/65711574#65711574 4 | 5 | -- Extra reading: 6 | -- https://medium.com/snowflake/visualizing-task-hierarchies-and-dependencies-in-snowflake-snowsight-d28298d0f0ed 7 | 8 | -- TODO: better permissions 9 | -- https://docs.snowflake.com/en/user-guide/tasks-intro.html#creating-a-task-administrator-role 10 | use role accountadmin; 11 | grant execute task on account to role sysadmin; 12 | use role sysadmin; 13 | 14 | -- stream so this task executes every minute, but only if there's new data 15 | create table just_timestamps_stream_table(value varchar); 16 | create stream just_timestamps_stream on table just_timestamps_stream_table; 17 | 18 | -- https://docs.snowflake.com/en/user-guide/tasks-intro.html 19 | create or replace task mytask_minute 20 | warehouse = test_small 21 | schedule = '1 MINUTE' 22 | when SYSTEM$STREAM_HAS_DATA('just_timestamps_stream') 23 | as 24 | -- consume stream so tasks doesn't execute again 25 | delete from just_timestamps_stream_table; 26 | 27 | alter task mytask_minute resume; 28 | 29 | insert into just_timestamps_stream_table values('trigger'); 30 | 31 | -- proving that it works 32 | select state, error_message, * 33 | from table(information_schema.task_history()) 34 | limit 5; 35 | 36 | -- now let's add dependent tasks 37 | alter task mytask_minute suspend; 38 | 39 | -- our goal is to insert new timestamps here 40 | create or replace table just_timestamps(ts timestamp, note varchar); 41 | 42 | create or replace task mytask_minute_child1 43 | warehouse = test_small 44 | after mytask_minute 45 | as 46 | insert into just_timestamps values(current_timestamp, 'child1'); 47 | 48 | create or replace task mytask_minute_child2 49 | warehouse = test_small 50 | after mytask_minute 51 | as 52 | insert into just_timestamps values(current_timestamp, 'child2'); 53 | 54 | alter task mytask_minute_child2 resume; 55 | alter task mytask_minute_child1 resume; 56 | alter task mytask_minute resume; 57 | 58 | -- trigger a new run with new data in the stream 59 | insert into just_timestamps_stream_table values('trigger'); 60 | 61 | -- it works! 62 | select state, name, scheduled_time, error_message, * 63 | from table(information_schema.task_history()) 64 | limit 5; 65 | 66 | -- data has been added here 67 | select * 68 | from just_timestamps 69 | order by ts desc; 70 | 71 | -- clean up? 72 | show tasks; 73 | alter task mytask_minute suspend; 74 | drop task mytask_minute; 75 | drop task mytask_minute_child1; 76 | drop task mytask_minute_child2; 77 | -------------------------------------------------------------------------------- /pivots/readme.md: -------------------------------------------------------------------------------- 1 | Dynamic PIVOTs in SQL with Snowflake 2 | -- 3 | 4 | See https://medium.com/@hoffa/dynamic-pivots-in-sql-with-snowflake-c763933987c 5 | 6 | Usage: 7 | --- 8 | ```sql 9 | select name, date_trunc(quarter, month) pivot_column, sum(month_views) pivot_value 10 | from hero_views 11 | group by 1,2 12 | ; 13 | 14 | call pivot_prev_results(); 15 | 16 | select * from table(result_scan(last_query_id(-2))); 17 | ``` 18 | 19 | Procedure: 20 | --- 21 | 22 | ```sql 23 | create or replace procedure pivot_prev_results() 24 | returns string 25 | language javascript 26 | execute as caller as 27 | $$ 28 | var cols_query = ` 29 | select '\\'' 30 | || listagg(distinct pivot_column, '\\',\\'') within group (order by pivot_column) 31 | || '\\'' 32 | from table(result_scan(last_query_id(-1)))`; 33 | var stmt1 = snowflake.createStatement({sqlText: cols_query}); 34 | var results1 = stmt1.execute(); 35 | results1.next(); 36 | var col_list = results1.getColumnValue(1); 37 | 38 | pivot_query = ` 39 | select * 40 | from (select * from table(result_scan(last_query_id(-2)))) 41 | pivot(max(pivot_value) for pivot_column in (${col_list})) 42 | ` 43 | var stmt2 = snowflake.createStatement({sqlText: pivot_query}); 44 | stmt2.execute(); 45 | return `select * from table(result_scan('${stmt2.getQueryId()}'));\n select * from table(result_scan(last_query_id(-2)));`; 46 | $$; 47 | ``` 48 | 49 | Sample data: 50 | --- 51 | ```sql 52 | create or replace table hero_views as 53 | select $1 name, $2::date month, $3 month_views 54 | from (values('Spider-Man','2020-04-01',210457), ('Spider-Man','2020-08-01',180055), ('Spider-Man','2020-12-01',229166), ('Spider-Man','2020-01-01',150171), ('Spider-Man','2020-07-01',164904), ('Spider-Man','2020-10-01',205147), ('Spider-Man','2020-05-01',191329), ('Spider-Man','2020-06-01',172506), ('Spider-Man','2020-09-01',175904), ('Spider-Man','2020-11-01',236432), ('Spider-Man','2020-03-01',157379), ('Spider-Man','2020-02-01',134859), ('Wonder Woman','2020-10-01',98388), ('Wonder Woman','2020-11-01',113600), ('Wonder Woman','2020-06-01',115926), ('Wonder Woman','2020-02-01',90333), ('Wonder Woman','2020-12-01',406326), ('Wonder Woman','2020-07-01',99840), ('Wonder Woman','2020-08-01',121413), ('Wonder Woman','2020-05-01',125235), ('Wonder Woman','2020-04-01',110816), ('Wonder Woman','2020-03-01',101583), ('Wonder Woman','2020-09-01',101168), ('Wonder Woman','2020-01-01',110806), ('Iron Man','2020-11-01',87757), ('Iron Man','2020-08-01',95862), ('Iron Man','2020-04-01',121403), ('Iron Man','2020-03-01',86143), ('Iron Man','2020-06-01',83922), ('Iron Man','2020-02-01',69272), ('Iron Man','2020-07-01',83316), ('Iron Man','2020-10-01',90943), ('Iron Man','2020-12-01',93141), ('Iron Man','2020-09-01',100696), ('Iron Man','2020-01-01',95296), ('Iron Man','2020-05-01',116757), ('Wolverine','2020-08-01',82151), ('Wolverine','2020-07-01',81343), ('Wolverine','2020-09-01',76360), ('Wolverine','2020-01-01',69570), ('Wolverine','2020-02-01',64213), ('Wolverine','2020-11-01',79048), ('Wolverine','2020-12-01',68448), ('Wolverine','2020-03-01',83920), ('Wolverine','2020-06-01',78275), ('Wolverine','2020-05-01',92548), ('Wolverine','2020-04-01',96679), ('Wolverine','2020-10-01',81325)) 55 | ; 56 | ``` 57 | -------------------------------------------------------------------------------- /open_source_boards/board_tenure.sql: -------------------------------------------------------------------------------- 1 | // https://medium.com/@hoffa/open-source-boards-and-tenure-terms-e8cadb02035 2 | 3 | with sheet4 as ( 4 | select $1 f, $2 x 5 | from (values('fsf', 'Richard Stallman 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 | Geoffrey Knauth 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 7 | Gerald Sussman 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 | Henry Poole 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 | Eben Moglen 1 1 1 1 1 1 10 | Lawrence Lessig 1 1 1 1 11 | Benjamin Mako Hill 1 1 1 1 1 1 1 1 1 1 1 1 1 12 | Hal Abelson 1 1 1 1 1 1 1 1 1 1 13 | Bradley Kuhn 1 1 1 1 1 1 1 1 14 | Peter Brown 1 1 1 15 | Matthew Garrett 1 1 16 | Kat Walsh 1 1 1 1 1 1 17 | Alexandre Oliva 1 1 18 | Ian Kelling 1 19 | Odile Bénassy 1'), ('python', 'David Ascher 1 1 1 1 1 1 1 20 | Paul Everitt 1 21 | Fredrik Lundh 1 22 | Tim Peters 1 1 1 1 1 1 1 1 1 1 1 1 1 23 | Guido van Rossum 1 1 1 1 24 | Greg Stein 1 1 1 25 | Thomas Wouters 1 1 1 1 1 1 26 | Jeremy Hylton 1 1 1 1 27 | Marc-André Lemburg 1 1 1 1 1 1 1 1 28 | Martin von Löwis 1 1 1 1 1 1 1 1 1 1 1 29 | Stephan Deibel 1 1 1 1 1 30 | Steve Holden 1 1 1 1 1 1 1 1 1 31 | Andrew Kuchling 1 1 1 1 1 32 | Brett Cannon 1 1 1 1 1 33 | David Goodger 1 1 1 34 | Raymond Hettinger 1 1 1 1 35 | James Tauber 1 1 1 1 36 | David Mertz 1 1 1 1 1 1 37 | Jeff Rush 1 1 1 38 | Doug Napoleone 1 1 1 1 39 | Jesse Noller 1 1 1 1 40 | Allison Randal 1 1 41 | Gloria Willadsen 1 1 42 | Brian Curtin 1 1 1 43 | Van Lindberg 1 1 1 1 1 1 1 1 1 44 | Jessica McKellar 1 1 1 45 | Alex Gaynor 1 1 1 46 | Lynn Root 1 1 1 47 | Nick Coghlan 1 1 48 | Kushal Das 1 1 1 1 1 1 49 | Selena Decklemann 1 50 | Travis Oliphant 1 51 | Naomi Ceder 1 1 1 1 1 52 | Diana Clarke 1 1 53 | Ashwini Oruganti 1 54 | Anna Ossowski 1 1 1 1 55 | Carrie Ann Philbin 1 1 56 | Carol Willing 1 1 57 | Annapoornima Koppad 1 58 | Jacqueline Kazil 1 1 1 1 1 59 | Lorena Mesa 1 1 1 1 60 | Trey Hunner 1 1 61 | Younggun Kim 1 62 | Eric Holscher 1 1 1 63 | Paul Hildebrandt 1 64 | Marlene Mhangami 1 1 1 1 65 | Kenneth Reitz 1 66 | Ewa Jodlowska 1 1 1 1 67 | Paola Katherine Pacheco 1 68 | Christopher Neugebauer 1 1 1 69 | Jeff Triplett 1 1 1 70 | Katie McLaughlin 1 1 1 71 | Jannis Leidel 1 1 72 | Nina Zakharenko 1 73 | Dustin Ingram 1 74 | '), ('apache', 'Brian Behlendorf 1 1 1 75 | Ken Coar 1 1 1 1 1 1 76 | Roy T. Fielding 1 1 1 1 1 1 1 1 1 77 | Jim Jagielski 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 78 | Ben Laurie 1 1 1 1 79 | Bill Stoddard 1 80 | Randy Terbush 1 1 81 | Dirk-Willem van Gulik 1 1 1 1 1 1 82 | Greg Stein 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 83 | Bill Stoddard 1 84 | Sam Ruby 1 1 1 1 1 1 1 1 1 1 1 1 1 1 85 | Mark Cox 1 86 | Geir Magnusson Jr. 1 1 1 1 87 | Stefano Mazzocchi 1 1 88 | Sander Striker 1 1 1 1 89 | Justin Erenkrantz 1 1 1 1 1 90 | Cliff Schmidt 1 91 | Henri Yandell 1 1 1 92 | J Aaron Farr 1 1 93 | William Rowe Jr. 1 1 94 | Henning Schmiedehausen 1 1 95 | Bertrand Delacretaz 1 1 1 1 1 1 1 1 1 1 1 96 | Shane Curcuru 1 1 1 1 1 1 1 1 1 1 97 | Doug Cutting 1 1 1 1 1 1 98 | Brian McCallister 1 99 | Brett Porter 1 1 1 1 1 1 1 1 1 100 | Noirin Shirley 1 101 | Lawrence Rosen 1 102 | Rich Bowen 1 1 1 1 1 1 103 | Ross Gardler 1 1 104 | Chris Mattmann 1 1 1 1 1 105 | David Nalley 1 106 | Isabel Drost-Fromm 1 1 107 | Marvin Humphrey 1 108 | Mark Thomas 1 1 1 109 | Phil Steitz 1 1 110 | Ted Dunning 1 1 1 111 | Roman Shaposhnik 1 1 112 | Danny Angus 1 113 | Myrle Krantz 1 114 | Daniel Ruggeri 1 115 | Craig L Russell 1 1 116 | Joan Touzet 1 117 | Niclas Hedhman 1 118 | Justin Mclean 1 119 | Patricia Shanahan 1') 120 | , ( 121 | 'osi', 'Matt Asay 1 122 | Ken Coar 1 1 1 123 | Danese Cooper 1 1 1 124 | Bruno Souza 1 1 1 1 1 1 125 | Rishab Aiyer Ghosh 1 1 126 | Raj Mathur 1 127 | Russell Nelson 1 1 1 128 | Nnenna Nwakanma 1 1 1 129 | Alolita Sharma 1 1 1 1 1 1 130 | Michael Tiemann 1 1 1 1 1 131 | Harshad Gune 1 1 1 1 1 1 132 | Martin Michlmayr 1 1 1 1 1 1 133 | Andrew C. Oliver 1 1 1 134 | Karl Fogel 1 1 1 1 135 | Mike Godwin 1 1 136 | Jim Jagielski 1 1 1 137 | Fabio Kon 1 1 1 138 | Simon Phipps 1 1 1 1 1 1 1 1 1 139 | Tony Wasserman 1 1 1 1 1 1 140 | Deborah Bryant 1 1 1 1 1 1 1 141 | Mike Milinkovich 1 1 1 1 1 142 | Luis Villa 1 1 1 143 | Richard Fontana 1 1 1 1 1 1 144 | Patrick Masson 1 1 1 1 1 1 1 145 | Leslie Hawthorn 1 1 1 146 | Alison Randal 1 1 1 1 1 147 | Stefano Zacchiroli 1 1 1 148 | Paul Tagliamonte 1 1 149 | Molly de Blanc 1 1 1 1 150 | Josh Simmons 1 1 1 1 1 151 | Italo Vignoli 1 1 1 1 152 | VM Brasseur 1 153 | Chris Lamb 1 1 1 1 154 | Faidon Liambotis 1 1 1 1 155 | Carol Smith 1 1 156 | Pamela Chestek 1 1 157 | Hong Phuc Dang 1 1 158 | Elana Hashman 1 1 159 | Tracy Hinds 1 1 160 | Megan Byrd-Sanicki 1' 161 | ))), 162 | unpivot as ( 163 | select f 164 | , split(y.value, '\t')[0]::string who, z.index+2000-5 year 165 | , row_number() over(partition by f, who order by year) years_served 166 | from sheet4 167 | , table(split_to_table(x, '\n')) y 168 | , table(split_to_table(y.value, '\t')) z 169 | where z.index>5 170 | and z.value='1' 171 | ) 172 | 173 | -- select * 174 | -- from unpivot; 175 | 176 | select f, year, avg(years_served) 177 | from unpivot 178 | group by 1,2 179 | order by 1,2 180 | 181 | ; 182 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------