|
| 1 | +/* |
| 2 | + * This file and its contents are licensed under the Apache License 2.0. |
| 3 | + * Please see the included NOTICE for copyright information and |
| 4 | + * LICENSE-APACHE for a copy of the license. |
| 5 | + */ |
| 6 | + |
| 7 | +#include <postgres.h> |
| 8 | + |
| 9 | +#include <catalog/pg_type.h> |
| 10 | +#include <fmgr.h> |
| 11 | +#include <nodes/makefuncs.h> |
| 12 | + |
| 13 | +#include "compat/compat.h" |
| 14 | + |
| 15 | +#include "alter_table_with_clause.h" |
| 16 | +#include "create_materialized_view_with_clause.h" |
| 17 | +#include "cross_module_fn.h" |
| 18 | +#include "ts_catalog/continuous_agg.h" |
| 19 | +#include "with_clause_parser.h" |
| 20 | + |
| 21 | +static const WithClauseDefinition continuous_aggregate_with_clause_def[] = { |
| 22 | + [CreateMaterializedViewFlagContinuous] = { |
| 23 | + .arg_names = {"continuous", NULL}, |
| 24 | + .type_id = BOOLOID, |
| 25 | + .default_val = (Datum)false, |
| 26 | + }, |
| 27 | + [CreateMaterializedViewFlagCreateGroupIndexes] = { |
| 28 | + .arg_names = {"create_group_indexes", NULL}, |
| 29 | + .type_id = BOOLOID, |
| 30 | + .default_val = (Datum)true, |
| 31 | + }, |
| 32 | + [CreateMaterializedViewFlagMaterializedOnly] = { |
| 33 | + .arg_names = {"materialized_only", NULL}, |
| 34 | + .type_id = BOOLOID, |
| 35 | + .default_val = (Datum)true, |
| 36 | + }, |
| 37 | + [CreateMaterializedViewFlagCompress] = { |
| 38 | + .arg_names = {"columnstore", "enable_columnstore", "compress", NULL}, |
| 39 | + .type_id = BOOLOID, |
| 40 | + }, |
| 41 | + [CreateMaterializedViewFlagFinalized] = { |
| 42 | + .arg_names = {"finalized", NULL}, |
| 43 | + .type_id = BOOLOID, |
| 44 | + .default_val = (Datum)true, |
| 45 | + }, |
| 46 | + [CreateMaterializedViewFlagChunkTimeInterval] = { |
| 47 | + .arg_names = {"chunk_time_interval", NULL}, |
| 48 | + .type_id = INTERVALOID, |
| 49 | + }, |
| 50 | + [CreateMaterializedViewFlagCompressSegmentBy] = { |
| 51 | + .arg_names = {"segmentby", "compress_segmentby", NULL}, |
| 52 | + .type_id = TEXTOID, |
| 53 | + }, |
| 54 | + [CreateMaterializedViewFlagCompressOrderBy] = { |
| 55 | + .arg_names = {"orderby", "compress_orderby", NULL}, |
| 56 | + .type_id = TEXTOID, |
| 57 | + }, |
| 58 | + [CreateMaterializedViewFlagCompressChunkTimeInterval] = { |
| 59 | + .arg_names = {"compress_chunk_time_interval", NULL}, |
| 60 | + .type_id = INTERVALOID, |
| 61 | + }, |
| 62 | +}; |
| 63 | + |
| 64 | +WithClauseResult * |
| 65 | +ts_create_materialized_view_with_clause_parse(const List *defelems) |
| 66 | +{ |
| 67 | + return ts_with_clauses_parse(defelems, |
| 68 | + continuous_aggregate_with_clause_def, |
| 69 | + TS_ARRAY_LEN(continuous_aggregate_with_clause_def)); |
| 70 | +} |
| 71 | + |
| 72 | +List * |
| 73 | +ts_continuous_agg_get_compression_defelems(const WithClauseResult *with_clauses) |
| 74 | +{ |
| 75 | + List *ret = NIL; |
| 76 | + |
| 77 | + for (int i = 0; i < AlterTableFlagsMax; i++) |
| 78 | + { |
| 79 | + int option_index = 0; |
| 80 | + switch (i) |
| 81 | + { |
| 82 | + case AlterTableFlagCompressEnabled: |
| 83 | + option_index = CreateMaterializedViewFlagCompress; |
| 84 | + break; |
| 85 | + case AlterTableFlagCompressSegmentBy: |
| 86 | + option_index = CreateMaterializedViewFlagCompressSegmentBy; |
| 87 | + break; |
| 88 | + case AlterTableFlagCompressOrderBy: |
| 89 | + option_index = CreateMaterializedViewFlagCompressOrderBy; |
| 90 | + break; |
| 91 | + case AlterTableFlagCompressChunkTimeInterval: |
| 92 | + option_index = CreateMaterializedViewFlagCompressChunkTimeInterval; |
| 93 | + break; |
| 94 | + default: |
| 95 | + elog(ERROR, "Unhandled compression option"); |
| 96 | + break; |
| 97 | + } |
| 98 | + |
| 99 | + const WithClauseResult *input = &with_clauses[option_index]; |
| 100 | + WithClauseDefinition def = continuous_aggregate_with_clause_def[option_index]; |
| 101 | + |
| 102 | + if (!input->is_default) |
| 103 | + { |
| 104 | + Node *value = (Node *) makeString(ts_with_clause_result_deparse_value(input)); |
| 105 | + DefElem *elem = makeDefElemExtended(EXTENSION_NAMESPACE, |
| 106 | + (char *) def.arg_names[0], |
| 107 | + value, |
| 108 | + DEFELEM_UNSPEC, |
| 109 | + -1); |
| 110 | + ret = lappend(ret, elem); |
| 111 | + } |
| 112 | + } |
| 113 | + return ret; |
| 114 | +} |
0 commit comments