(self, table)
| 790 | self.cluster.hive.warehouse_dir, db_name, table.name) |
| 791 | |
| 792 | def make_create_table_sql(self, table): |
| 793 | sql = super(ImpalaCursor, self).make_create_table_sql(table) |
| 794 | |
| 795 | if table.primary_keys: |
| 796 | if table.storage_format in ImpalaCursor.STORAGE_FORMATS_WITH_PRIMARY_KEYS: |
| 797 | # IMPALA-4424 adds support for parametrizing the partitions; for now, on our |
| 798 | # small scale, this is ok, especially since the model is to migrate tables from |
| 799 | # Impala into Postgres anyway. 3 was chosen for the buckets because our |
| 800 | # minicluster tends to have 3 tablet servers, but otherwise it's arbitrary and |
| 801 | # provides valid syntax for creating Kudu tables in Impala. |
| 802 | sql += '\nPARTITION BY HASH ({col}) PARTITIONS 3'.format( |
| 803 | col=table.primary_key_names[0]) |
| 804 | else: |
| 805 | raise Exception( |
| 806 | 'table representation has primary keys {keys} but is not in a format that ' |
| 807 | 'supports them: {storage_format}'.format( |
| 808 | keys=str(table.primary_key_names), |
| 809 | storage_format=table.storage_format)) |
| 810 | elif table.storage_format in ImpalaCursor.STORAGE_FORMATS_WITH_PRIMARY_KEYS: |
| 811 | raise Exception( |
| 812 | 'table representation has storage format {storage_format} ' |
| 813 | 'but does not have any primary keys'.format( |
| 814 | storage_format=table.storage_format)) |
| 815 | |
| 816 | if table.storage_format != 'TEXTFILE': |
| 817 | sql += "\nSTORED AS " + table.storage_format |
| 818 | if table.storage_location: |
| 819 | sql = sql.replace("CREATE TABLE", "CREATE EXTERNAL TABLE") |
| 820 | sql += "\nLOCATION '%s'" % table.storage_location |
| 821 | if table.storage_format == 'AVRO': |
| 822 | if table.schema_location: |
| 823 | sql += "\nTBLPROPERTIES ('avro.schema.url' = '%s')" % table.schema_location |
| 824 | else: |
| 825 | avro_schema = table.get_avro_schema() |
| 826 | if len(avro_schema) > 4000: |
| 827 | raise Exception("Avro schema exceeds 4000 character limit. Create a file" |
| 828 | " containing the schema instead and set 'table.schema_location'.") |
| 829 | sql += "\nTBLPROPERTIES ('avro.schema.literal' = '%s')" % avro_schema |
| 830 | return sql |
| 831 | |
| 832 | def get_sql_for_data_type(self, data_type): |
| 833 | if issubclass(data_type, String): |
nothing calls this directly
no test coverage detected