├── .gitignore ├── foreign_table_exposer.control ├── foreign_table_exposer--1.0.sql ├── Makefile ├── META.json ├── README.md ├── sql └── list_tables.sql ├── expected └── list_tables.out ├── foreign_table_exposer.c └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | foreign_table_exposer.o 2 | foreign_table_exposer.so 3 | results/*.out 4 | -------------------------------------------------------------------------------- /foreign_table_exposer.control: -------------------------------------------------------------------------------- 1 | # foreign_table_exposer extension 2 | comment = 'expose foreign tables as a regular table' 3 | default_version = '1.0' 4 | module_pathname = '$libdir/foreign_table_exposer' 5 | relocatable = true 6 | -------------------------------------------------------------------------------- /foreign_table_exposer--1.0.sql: -------------------------------------------------------------------------------- 1 | /* foreign_table_exposer/foreign_table_exposer--1.0.sql */ 2 | 3 | -- complain if script is sourced in psql, rather than via CREATE EXTENSION 4 | \echo Use "CREATE EXTENSION foreign_table_exposer" to load this file. \quit 5 | 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # foreign_table_exposer/Makefile 2 | 3 | MODULE_big = foreign_table_exposer 4 | OBJS = foreign_table_exposer.o 5 | EXTENSION = foreign_table_exposer 6 | DATA = foreign_table_exposer--1.0.sql 7 | PGFILEDESC = "foreign_table_exposer - expose foreign tables as a regular table" 8 | REGRESS = list_tables 9 | 10 | PG_CONFIG = pg_config 11 | PGXS := $(shell $(PG_CONFIG) --pgxs) 12 | include $(PGXS) 13 | 14 | -------------------------------------------------------------------------------- /META.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foreign_table_exposer", 3 | "abstract": "Expose foreign tables as a regular table", 4 | "description": "PostgreSQL extension which exposes foreign tables as a regular table.", 5 | "version": "1.0.0", 6 | "maintainer": "Mitsunori Komatsu ", 7 | "license": "apache_2_0", 8 | "provides": { 9 | "foreign_table_exposer": { 10 | "abstract": "Expose foreign tables as a regular table", 11 | "file": "foreign_table_exposer--1.0.sql", 12 | "docfile": "README.md", 13 | "version": "1.0.0" 14 | } 15 | }, 16 | "prereqs": { 17 | "runtime": { 18 | "requires": { 19 | "PostgreSQL": "9.3.0" 20 | } 21 | } 22 | }, 23 | "resources": { 24 | "bugtracker": { 25 | "web": "https://github.com/komamitsu/foreign_table_exposer/issues" 26 | }, 27 | "repository": { 28 | "url": "https://github.com/komamitsu/foreign_table_exposer.git", 29 | "web": "https://github.com/komamitsu/foreign_table_exposer/", 30 | "type": "git" 31 | } 32 | }, 33 | "generated_by": "Mitsunori Komatsu", 34 | "meta-spec": { 35 | "version": "1.0.0", 36 | "url": "http://pgxn.org/meta/spec.txt" 37 | }, 38 | "tags": [ 39 | "table", 40 | "plan", 41 | "fdw", 42 | "foreign data wrapper" 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # foreign_table_exposer 2 | 3 | This PostgreSQL extension exposes foreign tables like a normal table with rewriting Query tree. Some BI tools can't detect foreign tables since they don't consider them when getting table list from `pg_catalog.pg_class`. With this extension those BI tools can detect foreign tables as well as normal tables. 4 | 5 | ## Installation 6 | 7 | $ make 8 | $ sudo make install 9 | 10 | or 11 | 12 | $ pgxnclient install foreign_table_exposer 13 | 14 | ## Setup 15 | Write this line in your `postgresql.conf` and then restart PostgreSQL. 16 | 17 | shared_preload_libraries = 'foreign_table_exposer' 18 | 19 | Execute this statement when you want to enable this feature. 20 | 21 | CREATE EXTENSION foreign_table_exposer; 22 | 23 | ## Usage 24 | When you scan `pg_catalog.pg_class` with a predicate like `relkind in ('r', 'v')`, this extension automatically rewrites the query to include `'f'` (foreign table). 25 | 26 | postgres=# 27 | select 28 | relname, nspname, relkind 29 | from 30 | pg_catalog.pg_class c, 31 | pg_catalog.pg_namespace n 32 | where relkind in ('r', 'v') and 33 | nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') and 34 | n.oid = relnamespace order by nspname, relname; 35 | 36 | relname | nspname | relkind 37 | ------------------+---------+--------- 38 | normal_tbl | public | r 39 | foreign_tbl | public | f 40 | example_view | public | v 41 | (3 rows) 42 | 43 | -------------------------------------------------------------------------------- /sql/list_tables.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages = WARNING; 2 | 3 | CREATE EXTENSION postgres_fdw; 4 | 5 | CREATE SERVER ftex_test_foreign_server 6 | FOREIGN DATA WRAPPER postgres_fdw 7 | OPTIONS (host '192.0.2.1', port '5432', dbname 'foreign_db'); 8 | 9 | CREATE FOREIGN TABLE ftex_test_foreign_table (id serial NOT NULL, data text) 10 | SERVER ftex_test_foreign_server 11 | OPTIONS (schema_name 'some_schema', table_name 'some_table'); 12 | 13 | SELECT relname, nspname, relkind 14 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 15 | WHERE relkind IN ('r', 'v') 16 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 17 | AND n.oid = relnamespace 18 | ORDER BY nspname, relname; 19 | 20 | SELECT relname, nspname, relkind 21 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 22 | WHERE relkind IN ('v') 23 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 24 | AND n.oid = relnamespace 25 | ORDER BY nspname, relname; 26 | 27 | BEGIN; 28 | DECLARE "SQL_CUR0x0123456789ab" CURSOR FOR 29 | SELECT relname, nspname, relkind 30 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 31 | WHERE relkind IN ('r', 'v') 32 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 33 | AND n.oid = relnamespace 34 | ORDER BY nspname, relname; 35 | 36 | FETCH 100 IN "SQL_CUR0x0123456789ab"; 37 | 38 | CLOSE "SQL_CUR0x0123456789ab"; 39 | 40 | BEGIN; 41 | DECLARE "SQL_CUR0x0123456789ab" CURSOR FOR 42 | SELECT relname, nspname, relkind 43 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 44 | WHERE relkind IN ('v') 45 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 46 | AND n.oid = relnamespace 47 | ORDER BY nspname, relname; 48 | 49 | FETCH 100 IN "SQL_CUR0x0123456789ab"; 50 | 51 | CLOSE "SQL_CUR0x0123456789ab"; 52 | 53 | DROP FOREIGN TABLE ftex_test_foreign_table; 54 | 55 | DROP SERVER ftex_test_foreign_server; 56 | 57 | \d 58 | -------------------------------------------------------------------------------- /expected/list_tables.out: -------------------------------------------------------------------------------- 1 | SET client_min_messages = WARNING; 2 | LOG: statement: SET client_min_messages = WARNING; 3 | CREATE EXTENSION postgres_fdw; 4 | CREATE SERVER ftex_test_foreign_server 5 | FOREIGN DATA WRAPPER postgres_fdw 6 | OPTIONS (host '192.0.2.1', port '5432', dbname 'foreign_db'); 7 | CREATE FOREIGN TABLE ftex_test_foreign_table (id serial NOT NULL, data text) 8 | SERVER ftex_test_foreign_server 9 | OPTIONS (schema_name 'some_schema', table_name 'some_table'); 10 | SELECT relname, nspname, relkind 11 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 12 | WHERE relkind IN ('r', 'v') 13 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 14 | AND n.oid = relnamespace 15 | ORDER BY nspname, relname; 16 | relname | nspname | relkind 17 | -------------------------+---------+--------- 18 | ftex_test_foreign_table | public | f 19 | (1 row) 20 | 21 | SELECT relname, nspname, relkind 22 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 23 | WHERE relkind IN ('v') 24 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 25 | AND n.oid = relnamespace 26 | ORDER BY nspname, relname; 27 | relname | nspname | relkind 28 | ---------+---------+--------- 29 | (0 rows) 30 | 31 | BEGIN; 32 | DECLARE "SQL_CUR0x0123456789ab" CURSOR FOR 33 | SELECT relname, nspname, relkind 34 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 35 | WHERE relkind IN ('r', 'v') 36 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 37 | AND n.oid = relnamespace 38 | ORDER BY nspname, relname; 39 | FETCH 100 IN "SQL_CUR0x0123456789ab"; 40 | relname | nspname | relkind 41 | -------------------------+---------+--------- 42 | ftex_test_foreign_table | public | f 43 | (1 row) 44 | 45 | CLOSE "SQL_CUR0x0123456789ab"; 46 | BEGIN; 47 | WARNING: there is already a transaction in progress 48 | DECLARE "SQL_CUR0x0123456789ab" CURSOR FOR 49 | SELECT relname, nspname, relkind 50 | FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n 51 | WHERE relkind IN ('v') 52 | AND nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1') 53 | AND n.oid = relnamespace 54 | ORDER BY nspname, relname; 55 | FETCH 100 IN "SQL_CUR0x0123456789ab"; 56 | relname | nspname | relkind 57 | ---------+---------+--------- 58 | (0 rows) 59 | 60 | CLOSE "SQL_CUR0x0123456789ab"; 61 | DROP FOREIGN TABLE ftex_test_foreign_table; 62 | DROP SERVER ftex_test_foreign_server; 63 | \d 64 | List of relations 65 | Schema | Name | Type | Owner 66 | --------+------+------+------- 67 | (0 rows) 68 | 69 | -------------------------------------------------------------------------------- /foreign_table_exposer.c: -------------------------------------------------------------------------------- 1 | #include "postgres.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "access/hash.h" 8 | #include "executor/instrument.h" 9 | #include "funcapi.h" 10 | #include "mb/pg_wchar.h" 11 | #include "miscadmin.h" 12 | #include "parser/analyze.h" 13 | #include "parser/parsetree.h" 14 | #include "parser/scanner.h" 15 | #include "pgstat.h" 16 | #include "storage/fd.h" 17 | #include "storage/ipc.h" 18 | #include "storage/spin.h" 19 | #include "tcop/utility.h" 20 | 21 | #include "utils/rel.h" 22 | #include "utils/relcache.h" 23 | #include "utils/syscache.h" 24 | #include "utils/elog.h" 25 | #include "catalog/pg_namespace.h" 26 | #include "catalog/pg_type.h" 27 | #include "access/htup_details.h" 28 | #include "nodes/nodes.h" 29 | #include "nodes/pg_list.h" 30 | #include "nodes/nodeFuncs.h" 31 | #include "nodes/makefuncs.h" 32 | 33 | #define PG_CATALOG "pg_catalog" 34 | #define PG_CLASS "pg_class" 35 | #define COL_RELKIND "relkind" 36 | 37 | PG_MODULE_MAGIC; 38 | 39 | /* Saved hook values in case of unload */ 40 | static post_parse_analyze_hook_type prev_post_parse_analyze_hook = NULL; 41 | 42 | /*---- Function declarations ----*/ 43 | 44 | void _PG_init(void); 45 | void _PG_fini(void); 46 | 47 | static void fte_post_parse_analyse(ParseState *pstate, Query *query); 48 | static void rewrite_query(Query *query); 49 | static bool walker(Node *node, List *relkinds); 50 | 51 | /* 52 | * Module load callback 53 | */ 54 | void 55 | _PG_init(void) 56 | { 57 | /* 58 | * Install hooks. 59 | */ 60 | prev_post_parse_analyze_hook = post_parse_analyze_hook; 61 | post_parse_analyze_hook = fte_post_parse_analyse; 62 | } 63 | 64 | /* 65 | * Module unload callback 66 | */ 67 | void 68 | _PG_fini(void) 69 | { 70 | /* Uninstall hooks. */ 71 | post_parse_analyze_hook = prev_post_parse_analyze_hook; 72 | } 73 | 74 | /* 75 | * Post-parse-analysis hook: mark query with a queryId 76 | */ 77 | static void 78 | fte_post_parse_analyse(ParseState *pstate, Query *query) 79 | { 80 | if (prev_post_parse_analyze_hook) 81 | { 82 | prev_post_parse_analyze_hook(pstate, query); 83 | } 84 | 85 | rewrite_query(query); 86 | } 87 | 88 | typedef struct PgClassRelKindPos 89 | { 90 | Index varno; 91 | AttrNumber varattno; 92 | } PgClassRelKindPos; 93 | 94 | static void 95 | rewrite_query(Query *query) 96 | { 97 | int varno_index; 98 | ListCell *lc_rtable; 99 | List *relkinds = NIL; 100 | 101 | if (query->type != T_Query || query->commandType != CMD_SELECT || query->querySource != QSRC_ORIGINAL) 102 | { 103 | return; 104 | } 105 | 106 | varno_index = 1; 107 | foreach(lc_rtable, query->rtable) 108 | { 109 | bool is_pg_class = false; 110 | Relation rd; 111 | RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc_rtable); 112 | 113 | rd = RelationIdGetRelation(rte->relid); 114 | 115 | if (rd != NULL && rd->rd_rel != NULL) 116 | { 117 | HeapTuple tp = SearchSysCache1(NAMESPACEOID, ObjectIdGetDatum(rd->rd_rel->relnamespace)); 118 | if (HeapTupleIsValid(tp)) 119 | { 120 | Form_pg_namespace nsptup = (Form_pg_namespace) GETSTRUCT(tp); 121 | if (nsptup != NULL) 122 | { 123 | if (strcmp(NameStr(nsptup->nspname), PG_CATALOG) == 0 && 124 | strcmp(NameStr(rd->rd_rel->relname), PG_CLASS) == 0) 125 | { 126 | ereport(DEBUG1, (errmsg("Found pg_catalog.pg_class"))); 127 | is_pg_class = true; 128 | } 129 | } 130 | ReleaseSysCache(tp); 131 | } 132 | RelationClose(rd); 133 | } 134 | 135 | if (is_pg_class && rte->eref != NULL) { 136 | int varattrno_index = 1; 137 | ListCell *lc_colname; 138 | foreach(lc_colname, rte->eref->colnames) 139 | { 140 | char *colname = strVal(lfirst(lc_colname)); 141 | if (strcmp(colname, COL_RELKIND) == 0) 142 | { 143 | ereport(DEBUG1, (errmsg("Found pg_catalog.pg_class.relkind: [varno:%d, varattno:%d]", varno_index, varattrno_index))); 144 | PgClassRelKindPos *relkindPos = (PgClassRelKindPos*) palloc(sizeof(PgClassRelKindPos)); 145 | relkindPos->varno = varno_index; 146 | relkindPos->varattno = varattrno_index; 147 | relkinds = lappend(relkinds, relkindPos); 148 | } 149 | varattrno_index++; 150 | } 151 | } 152 | 153 | /* TODO: Take care of subquery properly */ 154 | if (rte->subquery != NULL) 155 | { 156 | rewrite_query(rte->subquery); 157 | } 158 | 159 | varno_index++; 160 | } 161 | 162 | if (relkinds != NIL && relkinds->length > 0 && query->jointree != NULL) 163 | { 164 | FromExpr *fromExpr = query->jointree; 165 | expression_tree_walker(fromExpr->quals, walker, relkinds); 166 | } 167 | } 168 | 169 | static 170 | bool walker(Node *node, List *relkinds) 171 | { 172 | if (node == NULL) 173 | { 174 | return false; 175 | } 176 | 177 | if (IsA(node, OpExpr)) 178 | { 179 | /* TODO */ 180 | } 181 | else if (IsA(node, ScalarArrayOpExpr)) 182 | { 183 | ScalarArrayOpExpr *arrayOpExpr = (ScalarArrayOpExpr*) node; 184 | if (arrayOpExpr->args->length == 2 && IsA(list_nth(arrayOpExpr->args, 0), Var) && IsA(list_nth(arrayOpExpr->args, 1), ArrayExpr)) 185 | { 186 | ListCell *lc_relkind; 187 | Var *var = (Var*) list_nth(arrayOpExpr->args, 0); 188 | ArrayExpr *array = (ArrayExpr*) list_nth(arrayOpExpr->args, 1); 189 | foreach(lc_relkind, relkinds) 190 | { 191 | PgClassRelKindPos *relkindPos = lfirst(lc_relkind); 192 | if (var->varno == relkindPos->varno && var->varattno == relkindPos->varattno) 193 | { 194 | bool regularTableExists = false; 195 | bool foreignTableExists = false; 196 | ListCell *lc_elm; 197 | foreach(lc_elm, array->elements) 198 | { 199 | Node *elm = (Node*)lfirst(lc_elm); 200 | if (IsA(elm, Const)) 201 | { 202 | Const *c = (Const*)elm; 203 | if (c->constbyval && c->constlen == 1 && c->consttype == CHAROID) 204 | { 205 | switch (DatumGetChar(c->constvalue)) 206 | { 207 | case RELKIND_RELATION: 208 | regularTableExists = true; 209 | break; 210 | case RELKIND_FOREIGN_TABLE: 211 | foreignTableExists = true; 212 | break; 213 | default: 214 | break; 215 | } 216 | } 217 | } 218 | } 219 | ereport(DEBUG1, (errmsg("regularTableExists=%d, foreignTableExists=%d", regularTableExists, foreignTableExists))); 220 | if (regularTableExists && !foreignTableExists) 221 | { 222 | array->elements = 223 | lappend(array->elements, 224 | makeConst(CHAROID, -1, InvalidOid, 1, CharGetDatum(RELKIND_FOREIGN_TABLE), false, true)); 225 | } 226 | } 227 | } 228 | } 229 | else 230 | { 231 | ereport(WARNING, (errmsg("arrayOpExpr->args has unexpected values: %s", nodeToString(arrayOpExpr->args)))); 232 | } 233 | } 234 | return expression_tree_walker(node, walker, (void *) relkinds); 235 | } 236 | 237 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------