58
58
#include "chunk_index.h"
59
59
#include "compression_with_clause.h"
60
60
#include "copy.h"
61
+ #include "create_table_with_clause.h"
61
62
#include "cross_module_fn.h"
62
63
#include "debug_assert.h"
63
64
#include "debug_point.h"
@@ -101,6 +102,19 @@ static ProcessUtilityContext last_process_utility_context = PROCESS_UTILITY_TOPL
101
102
static DDLResult process_altertable_set_options (AlterTableCmd * cmd , Hypertable * ht );
102
103
static DDLResult process_altertable_reset_options (AlterTableCmd * cmd , Hypertable * ht );
103
104
105
+ static Oid
106
+ get_sizing_func_oid ()
107
+ {
108
+ const char * sizing_func_name = "calculate_chunk_interval" ;
109
+ const int sizing_func_nargs = 3 ;
110
+ static Oid sizing_func_arg_types [] = { INT4OID , INT8OID , INT8OID };
111
+
112
+ return ts_get_function_oid (sizing_func_name ,
113
+ INTERNAL_SCHEMA_NAME ,
114
+ sizing_func_nargs ,
115
+ sizing_func_arg_types );
116
+ }
117
+
104
118
/* Call the default ProcessUtility and handle PostgreSQL version differences */
105
119
static void
106
120
prev_ProcessUtility (ProcessUtilityArgs * args )
@@ -3665,6 +3679,13 @@ process_cluster_start(ProcessUtilityArgs *args)
3665
3679
return result ;
3666
3680
}
3667
3681
3682
+ typedef struct CreateTableInfo
3683
+ {
3684
+ bool hypertable ;
3685
+ NameData time_column ;
3686
+ } CreateTableInfo ;
3687
+
3688
+ static CreateTableInfo create_table_info = { 0 };
3668
3689
/*
3669
3690
* Process create table statements.
3670
3691
*
@@ -3709,6 +3730,34 @@ process_create_table_end(Node *parsetree)
3709
3730
break ;
3710
3731
}
3711
3732
}
3733
+
3734
+ if (true)
3735
+ {
3736
+ Oid table_relid = RangeVarGetRelid (stmt -> relation , NoLock , true);
3737
+
3738
+ DimensionInfo * open_dim_info =
3739
+ ts_dimension_info_create_open (table_relid ,
3740
+ & create_table_info .time_column , /* column name */
3741
+ -1 , /* interval */
3742
+ InvalidOid , /* interval type */
3743
+ InvalidOid /* partitioning func */
3744
+ );
3745
+
3746
+ ChunkSizingInfo chunk_sizing_info = {
3747
+ .table_relid = table_relid ,
3748
+ .func = get_sizing_func_oid (),
3749
+ .colname = NameStr (create_table_info .time_column ),
3750
+ };
3751
+
3752
+ ts_hypertable_create_from_info (table_relid ,
3753
+ INVALID_HYPERTABLE_ID ,
3754
+ 0 , /* flags */
3755
+ open_dim_info , /* open_dim_info */
3756
+ NULL , /* closed_dim_info */
3757
+ NULL , /* associated_schema_name */
3758
+ NULL , /* associated_table_prefix */
3759
+ & chunk_sizing_info );
3760
+ }
3712
3761
}
3713
3762
3714
3763
static inline const char *
@@ -4912,6 +4961,7 @@ process_create_stmt(ProcessUtilityArgs *args)
4912
4961
{
4913
4962
CreateStmt * stmt = castNode (CreateStmt , args -> parsetree );
4914
4963
4964
+ #if PG15_GE
4915
4965
if (stmt -> accessMethod && strcmp (stmt -> accessMethod , TS_HYPERCORE_TAM_NAME ) == 0 )
4916
4966
ereport (ERROR ,
4917
4967
errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -4929,6 +4979,22 @@ process_create_stmt(ProcessUtilityArgs *args)
4929
4979
errhint ("It does not make sense to set the default access method for all "
4930
4980
"tables to \"%s\" since it is only supported for hypertables." ,
4931
4981
TS_HYPERCORE_TAM_NAME ));
4982
+ #endif
4983
+
4984
+ List * pg_options = NIL , * hypertable_options = NIL ;
4985
+ ts_with_clause_filter (stmt -> options , & hypertable_options , & pg_options );
4986
+ stmt -> options = pg_options ;
4987
+
4988
+ if (hypertable_options )
4989
+ {
4990
+ WithClauseResult * parsed_with_clauses =
4991
+ ts_create_table_with_clause_parse (hypertable_options );
4992
+ }
4993
+
4994
+ create_table_info .hypertable =
4995
+ DatumGetBool (parsed_with_clauses [CreateTableFlagHypertable ].parsed );
4996
+ namestrcpy (& create_table_info .time_column ,
4997
+ TextDatumGetCString (parsed_with_clauses [CreateTableFlagTimeColumn ].parsed ));
4932
4998
4933
4999
return DDL_CONTINUE ;
4934
5000
}
0 commit comments