1
1
/*
2
2
* GridDB Foreign Data Wrapper
3
3
*
4
- * Portions Copyright (c) 2018 , TOSHIBA CORPORATION
4
+ * Portions Copyright (c) 2020 , TOSHIBA CORPORATION
5
5
*
6
6
* IDENTIFICATION
7
7
* deparse.c
32
32
#include "utils/rel.h"
33
33
#include "utils/relcache.h"
34
34
#include "utils/syscache.h"
35
+ #include "time.h"
35
36
36
37
/*
37
38
* Global context for foreign_expr_walker's search of an expression tree.
@@ -180,7 +181,7 @@ griddb_deparse_select(StringInfo buf,
180
181
* Core code already has some lock on each rel being planned, so we can
181
182
* use NoLock here.
182
183
*/
183
- rel = heap_open (rte -> relid , NoLock );
184
+ rel = table_open (rte -> relid , NoLock );
184
185
185
186
appendStringInfoString (buf , "SELECT " );
186
187
griddb_deparse_target_list (buf , root , baserel -> relid , rel ,
@@ -202,7 +203,7 @@ griddb_deparse_select(StringInfo buf,
202
203
if (pathkeys )
203
204
griddb_append_order_by_clause (pathkeys , & context );
204
205
205
- heap_close (rel , NoLock );
206
+ table_close (rel , NoLock );
206
207
}
207
208
208
209
/*
@@ -582,7 +583,11 @@ griddb_deparse_func_expr(FuncExpr *node, deparse_expr_cxt *context)
582
583
{
583
584
if (!first )
584
585
appendStringInfoString (buf , ", " );
586
+ #if (PG_VERSION_NUM >= 130000 )
587
+ if (use_variadic && lnext (node -> args , arg ) == NULL )
588
+ #else
585
589
if (use_variadic && lnext (arg ) == NULL )
590
+ #endif
586
591
elog (ERROR , "VARIADIC is not supported" );
587
592
deparseExpr ((Expr * ) lfirst (arg ), context );
588
593
first = false;
@@ -747,16 +752,31 @@ griddb_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
747
752
if (strcmp (opname , "<>" ) == 0 )
748
753
notIn = true;
749
754
755
+ arg1 = linitial (node -> args );
750
756
arg2 = lsecond (node -> args );
751
757
c = (Const * ) arg2 ;
752
758
Assert (nodeTag ((Node * ) arg2 ) == T_Const || c -> constisnull );
753
759
754
760
getTypeOutputInfo (c -> consttype ,
755
761
& typoutput , & typIsVarlena );
756
762
extval = OidOutputFunctionCall (typoutput , c -> constvalue );
757
- isstr = true;
758
- if (c -> consttype == INT4ARRAYOID || c -> consttype == OIDARRAYOID )
759
- isstr = false;
763
+ switch (c -> consttype )
764
+ {
765
+ case BOOLARRAYOID :
766
+ case INT8ARRAYOID :
767
+ case INT2ARRAYOID :
768
+ case INT4ARRAYOID :
769
+ case OIDARRAYOID :
770
+ case FLOAT4ARRAYOID :
771
+ case FLOAT8ARRAYOID :
772
+ case TIMESTAMPARRAYOID :
773
+ case TIMESTAMPTZARRAYOID :
774
+ isstr = false;
775
+ break ;
776
+ default :
777
+ isstr = true;
778
+ break ;
779
+ }
760
780
761
781
/* Deparse right operand. */
762
782
deparseLeft = true;
@@ -772,7 +792,12 @@ griddb_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
772
792
/* Deparse left operand. */
773
793
if (deparseLeft )
774
794
{
775
- arg1 = linitial (node -> args );
795
+ /* No need deparse bool column */
796
+ if (c -> consttype == BOOLARRAYOID )
797
+ {
798
+ deparseLeft = false;
799
+ continue ;
800
+ }
776
801
deparseExpr (arg1 , context );
777
802
if (notIn )
778
803
appendStringInfo (buf , " <> " );
@@ -812,9 +837,62 @@ griddb_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
812
837
appendStringInfo (buf , " AND " );
813
838
else
814
839
appendStringInfo (buf , " OR " );
840
+
841
+ /* No need deparse bool column */
842
+ if (c -> consttype == BOOLARRAYOID )
843
+ {
844
+ deparseLeft = false;
845
+ continue ;
846
+ }
847
+
815
848
deparseLeft = true;
816
849
continue ;
817
850
}
851
+
852
+ /* When compare with timestamp column, need to convert and cast to TIMESTAMP */
853
+ if (c -> consttype == TIMESTAMPARRAYOID || c -> consttype == TIMESTAMPTZARRAYOID )
854
+ {
855
+ char timestamp [MAXDATELEN + 1 ];
856
+ char chtime [MAXDATELEN + 1 ] = {0 };
857
+ struct tm tm ;
858
+ int j = 0 ;
859
+
860
+ for (;; valptr ++ )
861
+ {
862
+ if (* valptr == '\"' && !isEscape )
863
+ {
864
+ inString = !inString ;
865
+ break ;
866
+ }
867
+ chtime [j ] = * valptr ;
868
+ j ++ ;
869
+ }
870
+ i += j ;
871
+
872
+ /* Format of chtime is YYYY-MM-DD HH:MM:SS */
873
+ strptime (chtime , "%Y-%m-%d %H:%M:%S" , & tm );
874
+ griddb_convert_pg2gs_timestamp_string (time_t_to_timestamptz (timegm (& tm )), timestamp );
875
+ appendStringInfoString (buf , "TIMESTAMP(" );
876
+ griddb_deparse_string_literal (buf , timestamp );
877
+ appendStringInfoString (buf , ")" );
878
+ continue ;
879
+ }
880
+
881
+ /*
882
+ * GridDB not support compare bool column with true, false.
883
+ * Only support column or NOT column
884
+ */
885
+ if (c -> consttype == BOOLARRAYOID )
886
+ {
887
+ appendStringInfoChar (buf , '(' );
888
+ if (ch == 'f' )
889
+ appendStringInfoString (buf , "NOT " );
890
+
891
+ deparseExpr (arg1 , context );
892
+ appendStringInfoChar (buf , ')' );
893
+ continue ;
894
+ }
895
+
818
896
appendStringInfoChar (buf , ch );
819
897
}
820
898
if (isstr )
@@ -1355,7 +1433,7 @@ foreign_expr_walker(Node *node,
1355
1433
* Returns true if given expr is safe to evaluate on the foreign server.
1356
1434
*/
1357
1435
bool
1358
- is_foreign_expr (PlannerInfo * root ,
1436
+ griddb_is_foreign_expr (PlannerInfo * root ,
1359
1437
RelOptInfo * baserel ,
1360
1438
Expr * expr )
1361
1439
{
@@ -1414,7 +1492,7 @@ griddb_append_order_by_clause(List *pathkeys, deparse_expr_cxt *context)
1414
1492
PathKey * pathkey = (PathKey * ) lfirst (lcell );
1415
1493
Expr * em_expr ;
1416
1494
1417
- em_expr = find_em_expr_for_rel (pathkey -> pk_eclass , baserel );
1495
+ em_expr = griddb_find_em_expr_for_rel (pathkey -> pk_eclass , baserel );
1418
1496
Assert (em_expr != NULL );
1419
1497
1420
1498
appendStringInfoString (buf , delim );
@@ -1518,7 +1596,7 @@ griddb_classify_conditions(PlannerInfo *root,
1518
1596
{
1519
1597
RestrictInfo * ri = (RestrictInfo * ) lfirst (lc );
1520
1598
1521
- if (is_foreign_expr (root , baserel , ri -> clause ))
1599
+ if (griddb_is_foreign_expr (root , baserel , ri -> clause ))
1522
1600
* remote_conds = lappend (* remote_conds , ri );
1523
1601
else
1524
1602
* local_conds = lappend (* local_conds , ri );
0 commit comments