@@ -1167,6 +1167,44 @@ static Node *make_int_const(int i, int location) {
1167
1167
return (Node * )n ;
1168
1168
}
1169
1169
1170
+ static char *
1171
+ lookup_vertex_label_relname (ParseState * pstate , const char * label , bool is_default_label )
1172
+ {
1173
+ Datum label_lquery ;
1174
+ if (is_default_label )
1175
+ label_lquery = DirectFunctionCall1 (ltree_in , CStringGetDatum (label ));
1176
+ else
1177
+ label_lquery = DirectFunctionCall2 (ltree_addltree ,
1178
+ DirectFunctionCall1 (ltree_in , CStringGetDatum (AG_DEFAULT_LABEL_VERTEX )),
1179
+ DirectFunctionCall1 (ltree_in , CStringGetDatum (label )));
1180
+
1181
+ int ltq_query_args [2 ];
1182
+ ltq_query_args [0 ] = LookupTypeNameOid (pstate , makeTypeNameFromNameList (list_make2 (makeString ("public" ), makeString ("ltree" ))), false);
1183
+ ltq_query_args [1 ] = LookupTypeNameOid (pstate , makeTypeNameFromNameList (list_make2 (makeString ("public" ), makeString ("ltree" ))), false);
1184
+
1185
+ Oid ltree_contains_oid = LookupFuncName (list_make2 (makeString ("public" ), makeString ("ltree_risparent" )), 2 , & ltq_query_args , false);
1186
+
1187
+ ScanKeyData scan_keys [1 ];
1188
+ ScanKeyInit (& scan_keys [0 ], Anum_ag_label_label_path , BTEqualStrategyNumber , ltree_contains_oid , label_lquery );
1189
+
1190
+ Relation label_catalog = table_open (ag_label_relation_id (), ShareLock );
1191
+ SysScanDesc scan_desc = systable_beginscan (label_catalog , ag_label_label_index_id (), true, NULL , 1 , scan_keys );
1192
+
1193
+ HeapTuple tuple = systable_getnext (scan_desc );
1194
+
1195
+ if (!HeapTupleIsValid (tuple ))
1196
+ ereport (ERROR ,
1197
+ (errcode (ERRCODE_UNDEFINED_SCHEMA ),
1198
+ errmsg ("not found %s" , label )));
1199
+
1200
+ bool is_null ;
1201
+ Datum rel_name = heap_getattr (tuple , Anum_ag_label_name , RelationGetDescr (label_catalog ), & is_null );
1202
+
1203
+ systable_endscan (scan_desc );
1204
+ table_close (label_catalog , ShareLock );
1205
+
1206
+ return rel_name ;
1207
+ }
1170
1208
1171
1209
static void transform_match_pattern (cypher_parsestate * cpstate , Query * query , List * pattern , Node * where ) {
1172
1210
ParseState * pstate = (ParseState * )cpstate ;
@@ -1234,40 +1272,7 @@ static void transform_match_pattern(cypher_parsestate *cpstate, Query *query, Li
1234
1272
schema_name = get_graph_namespace_name (cpstate -> graph_name );
1235
1273
1236
1274
// XXX: LTree Labeling Project, first code is here
1237
- Datum label_lquery ;
1238
- if (is_default_label )
1239
- label_lquery = DirectFunctionCall1 (ltree_in , CStringGetDatum (node -> label ));
1240
- else
1241
- label_lquery = DirectFunctionCall2 (ltree_addltree ,
1242
- DirectFunctionCall1 (ltree_in , CStringGetDatum (AG_DEFAULT_LABEL_VERTEX )),
1243
- DirectFunctionCall1 (ltree_in , CStringGetDatum (node -> label )));
1244
-
1245
-
1246
-
1247
- int ltq_query_args [2 ];
1248
- ltq_query_args [0 ] = LookupTypeNameOid (pstate , makeTypeNameFromNameList (list_make2 (makeString ("public" ), makeString ("ltree" ))), false);
1249
- ltq_query_args [1 ] = LookupTypeNameOid (pstate , makeTypeNameFromNameList (list_make2 (makeString ("public" ), makeString ("ltree" ))), false);
1250
-
1251
- Oid ltree_contains_oid = LookupFuncName (list_make2 (makeString ("public" ), makeString ("ltree_risparent" )), 2 , & ltq_query_args , false);
1252
-
1253
- ScanKeyData scan_keys [1 ];
1254
- ScanKeyInit (& scan_keys [0 ], Anum_ag_label_label_path , BTEqualStrategyNumber , ltree_contains_oid , label_lquery );
1255
-
1256
- Relation label_catalog = table_open (ag_label_relation_id (), ShareLock );
1257
- SysScanDesc scan_desc = systable_beginscan (label_catalog , ag_label_label_index_id (), true, NULL , 1 , scan_keys );
1258
-
1259
- HeapTuple tuple = systable_getnext (scan_desc );
1260
-
1261
- if (!HeapTupleIsValid (tuple ))
1262
- ereport (ERROR ,
1263
- (errcode (ERRCODE_UNDEFINED_SCHEMA ),
1264
- errmsg ("not found %s" , node -> label )));
1265
-
1266
- bool is_null ;
1267
- rel_name = heap_getattr (tuple , Anum_ag_label_name , RelationGetDescr (label_catalog ), & is_null );
1268
-
1269
- systable_endscan (scan_desc );
1270
- table_close (label_catalog , ShareLock );
1275
+ char * rel_name = lookup_vertex_label_relname (pstate , node -> label , is_default_label );
1271
1276
1272
1277
//rel_name = get_label_relation_name(node->label, cpstate->graph_oid);
1273
1278
label_range_var = makeRangeVar (schema_name , rel_name , -1 );
0 commit comments