From d80f0860c7b4b587d4243ec41cedbd4b99f5b9b6 Mon Sep 17 00:00:00 2001 From: John Gemignani Date: Mon, 3 Jun 2024 16:16:41 -0700 Subject: [PATCH] Fix agtype_build_map to allow more than 50 pairs (#1901) Fixed agtype_build_map to allow objects to be created with more than 50 pairs. This is a PostgreSQL limitation on the number of function arguments. To achieve this, the agtype_add, aka concat operator, was used to concat objects together when the limit was reached for the number of arguments. Added regression tests. --- regress/expected/expr.out | 79 ++++++++++++++++++ regress/sql/expr.sql | 13 +++ src/backend/parser/cypher_expr.c | 136 +++++++++++++++++++++++++------ 3 files changed, 202 insertions(+), 26 deletions(-) diff --git a/regress/expected/expr.out b/regress/expected/expr.out index 36c081438..9df566804 100644 --- a/regress/expected/expr.out +++ b/regress/expected/expr.out @@ -8347,9 +8347,88 @@ SELECT agtype_to_int8(bool('neither')); ERROR: invalid input syntax for type boolean: "neither" LINE 1: SELECT agtype_to_int8(bool('neither')); ^ +-- Test expanded map operator +SELECT * FROM create_graph('expanded_map'); +NOTICE: graph "expanded_map" has been created + create_graph +-------------- + +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48} ) RETURN u $$) as (result agtype); + result +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710657, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49} ) RETURN u $$) as (result agtype); + result +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710658, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50} ) RETURN u $$) as (result agtype); + result +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710659, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51} ) RETURN u $$) as (result agtype); + result +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710660, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98} ) RETURN u $$) as (result agtype); + result +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710661, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99} ) RETURN u $$) as (result agtype); + result +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710662, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99, n100: 100} ) RETURN u $$) as (result agtype); + result +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710663, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99, "n100": 100}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99, n100: 100, n101: 101} ) RETURN u $$) as (result agtype); + result +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710664, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99, "n100": 100, "n101": 101}}::vertex +(1 row) + +SELECT * FROM cypher('expanded_map', $$ MATCH (u) RETURN u $$) as (result agtype); + result +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 281474976710657, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48}}::vertex + {"id": 281474976710658, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49}}::vertex + {"id": 281474976710659, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50}}::vertex + {"id": 281474976710660, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51}}::vertex + {"id": 281474976710661, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98}}::vertex + {"id": 281474976710662, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99}}::vertex + {"id": 281474976710663, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99, "n100": 100}}::vertex + {"id": 281474976710664, "label": "", "properties": {"n0": 0, "n1": 1, "n2": 2, "n3": 3, "n4": 4, "n5": 5, "n6": 6, "n7": 7, "n8": 8, "n9": 9, "n10": 10, "n11": 11, "n12": 12, "n13": 13, "n14": 14, "n15": 15, "n16": 16, "n17": 17, "n18": 18, "n19": 19, "n20": 20, "n21": 21, "n22": 22, "n23": 23, "n24": 24, "n25": 25, "n26": 26, "n27": 27, "n28": 28, "n29": 29, "n30": 30, "n31": 31, "n32": 32, "n33": 33, "n34": 34, "n35": 35, "n36": 36, "n37": 37, "n38": 38, "n39": 39, "n40": 40, "n41": 41, "n42": 42, "n43": 43, "n44": 44, "n45": 45, "n46": 46, "n47": 47, "n48": 48, "n49": 49, "n50": 50, "n51": 51, "n52": 52, "n53": 53, "n54": 54, "n55": 55, "n56": 56, "n57": 57, "n58": 58, "n59": 59, "n60": 60, "n61": 61, "n62": 62, "n63": 63, "n64": 64, "n65": 65, "n66": 66, "n67": 67, "n68": 68, "n69": 69, "n70": 70, "n71": 71, "n72": 72, "n73": 73, "n74": 74, "n75": 75, "n76": 76, "n77": 77, "n78": 78, "n79": 79, "n80": 80, "n81": 81, "n82": 82, "n83": 83, "n84": 84, "n85": 85, "n86": 86, "n87": 87, "n88": 88, "n89": 89, "n90": 90, "n91": 91, "n92": 92, "n93": 93, "n94": 94, "n95": 95, "n96": 96, "n97": 97, "n98": 98, "n99": 99, "n100": 100, "n101": 101}}::vertex +(8 rows) + -- -- Cleanup -- +SELECT * FROM drop_graph('expanded_map', true); +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table expanded_map._ag_label_vertex +drop cascades to table expanded_map._ag_label_edge +NOTICE: graph "expanded_map" has been dropped + drop_graph +------------ + +(1 row) + SELECT * FROM drop_graph('issue_1124', true); NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table issue_1124._ag_label_vertex diff --git a/regress/sql/expr.sql b/regress/sql/expr.sql index 11635fac2..3d9b44c11 100644 --- a/regress/sql/expr.sql +++ b/regress/sql/expr.sql @@ -3412,9 +3412,22 @@ SELECT agtype_to_int2(bool('neither')); SELECT agtype_to_int4(bool('neither')); SELECT agtype_to_int8(bool('neither')); +-- Test expanded map operator +SELECT * FROM create_graph('expanded_map'); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99, n100: 100} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ CREATE (u {n0: 0, n1: 1, n2: 2, n3: 3, n4: 4, n5: 5, n6: 6, n7: 7, n8: 8, n9: 9, n10: 10, n11: 11, n12: 12, n13: 13, n14: 14, n15: 15, n16: 16, n17: 17, n18: 18, n19: 19, n20: 20, n21: 21, n22: 22, n23: 23, n24: 24, n25: 25, n26: 26, n27: 27, n28: 28, n29: 29, n30: 30, n31: 31, n32: 32, n33: 33, n34: 34, n35: 35, n36: 36, n37: 37, n38: 38, n39: 39, n40: 40, n41: 41, n42: 42, n43: 43, n44: 44, n45: 45, n46: 46, n47: 47, n48: 48, n49: 49, n50: 50, n51: 51, n52: 52, n53: 53, n54: 54, n55: 55, n56: 56, n57: 57, n58: 58, n59: 59, n60: 60, n61: 61, n62: 62, n63: 63, n64: 64, n65: 65, n66: 66, n67: 67, n68: 68, n69: 69, n70: 70, n71: 71, n72: 72, n73: 73, n74: 74, n75: 75, n76: 76, n77: 77, n78: 78, n79: 79, n80: 80, n81: 81, n82: 82, n83: 83, n84: 84, n85: 85, n86: 86, n87: 87, n88: 88, n89: 89, n90: 90, n91: 91, n92: 92, n93: 93, n94: 94, n95: 95, n96: 96, n97: 97, n98: 98, n99: 99, n100: 100, n101: 101} ) RETURN u $$) as (result agtype); +SELECT * FROM cypher('expanded_map', $$ MATCH (u) RETURN u $$) as (result agtype); + -- -- Cleanup -- +SELECT * FROM drop_graph('expanded_map', true); SELECT * FROM drop_graph('issue_1124', true); SELECT * FROM drop_graph('issue_1303', true); SELECT * FROM drop_graph('graph_395', true); diff --git a/src/backend/parser/cypher_expr.c b/src/backend/parser/cypher_expr.c index de9fcd16d..1ba2b7ee4 100644 --- a/src/backend/parser/cypher_expr.c +++ b/src/backend/parser/cypher_expr.c @@ -993,32 +993,114 @@ static Node *transform_cypher_map_projection(cypher_parsestate *cpstate, } } +/* + * Helper function to transform a cypher map into an agtype map. The function + * will use agtype_add to concatenate the argument list when the number of + * parameters (keys and values) exceeds 100, a PG limitation. + */ static Node *transform_cypher_map(cypher_parsestate *cpstate, cypher_map *cm) { ParseState *pstate = (ParseState *)cpstate; - List *newkeyvals = NIL; - ListCell *le; - FuncExpr *fexpr; - Oid func_oid; + List *newkeyvals_args = NIL; + ListCell *le = NULL; + FuncExpr *fexpr = NULL; + FuncExpr *aa_lhs_arg = NULL; + Oid abm_func_oid = InvalidOid; + Oid aa_func_oid = InvalidOid; + int nkeyvals = 0; + int i = 0; + + /* get the number of keys and values */ + nkeyvals = list_length(cm->keyvals); - Assert(list_length(cm->keyvals) % 2 == 0); + /* error out if it isn't even */ + if (nkeyvals % 2 != 0) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("number of keys does not match number of values"))); + } + + if (nkeyvals == 0) + { + abm_func_oid = get_ag_func_oid("agtype_build_map", 0); + } + else if (!cm->keep_null) + { + abm_func_oid = get_ag_func_oid("agtype_build_map_nonull", 1, ANYOID); + } + else + { + abm_func_oid = get_ag_func_oid("agtype_build_map", 1, ANYOID); + } + /* get the concat function oid, if necessary */ + if (nkeyvals > 100) + { + aa_func_oid = get_ag_func_oid("agtype_add", 2, AGTYPEOID, AGTYPEOID); + } + + /* get the key/val list */ le = list_head(cm->keyvals); + /* while we have key/val to process */ while (le != NULL) { - Node *key; - Node *val; - Node *newval; + Node *key = NULL; + Node *val = NULL; + Node *newval = NULL; ParseCallbackState pcbstate; - Const *newkey; + Const *newkey = NULL; + /* get the key */ key = lfirst(le); le = lnext(cm->keyvals, le); + /* get the value */ val = lfirst(le); le = lnext(cm->keyvals, le); + /* transform the value */ newval = transform_cypher_expr_recurse(cpstate, val); + /* + * If we have more than 50 key/value pairs, 100 elements, we will need + * to add in the list concatenation function. + */ + if (i >= 50) + { + /* build the object for the first 50 pairs for concat */ + fexpr = makeFuncExpr(abm_func_oid, AGTYPEOID, newkeyvals_args, + InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); + fexpr->location = cm->location; + + /* initial case, set up for concatenating 2 lists */ + if (aa_lhs_arg == NULL) + { + aa_lhs_arg = fexpr; + } + /* + * For every other case, concatenate the list on to the previous + * concatenate operation. + */ + else + { + List *aa_args = list_make2(aa_lhs_arg, fexpr); + + fexpr = makeFuncExpr(aa_func_oid, AGTYPEOID, aa_args, + InvalidOid, InvalidOid, + COERCE_EXPLICIT_CALL); + fexpr->location = cm->location; + + /* set the lhs to the concatenation operation */ + aa_lhs_arg = fexpr; + } + + /* reset for the next 50 pairs */ + newkeyvals_args = NIL; + i = 0; + fexpr = NULL; + } + + /* build and append the transformed key/val pair */ setup_parser_errposition_callback(&pcbstate, pstate, cm->location); // typtypmod, typcollation, typlen, and typbyval of agtype are // hard-coded. @@ -1026,33 +1108,35 @@ static Node *transform_cypher_map(cypher_parsestate *cpstate, cypher_map *cm) CStringGetTextDatum(strVal(key)), false, false); cancel_parser_errposition_callback(&pcbstate); - newkeyvals = lappend(lappend(newkeyvals, newkey), newval); - } + newkeyvals_args = lappend(lappend(newkeyvals_args, newkey), newval); - if (list_length(newkeyvals) == 0) - { - func_oid = get_ag_func_oid("agtype_build_map", 0); - } - else if (!cm->keep_null) - { - func_oid = get_ag_func_oid("agtype_build_map_nonull", 1, ANYOID); - } - else - { - func_oid = get_ag_func_oid("agtype_build_map", 1, ANYOID); + i++; } - fexpr = makeFuncExpr(func_oid, AGTYPEOID, newkeyvals, InvalidOid, + /* now build the final map function */ + fexpr = makeFuncExpr(abm_func_oid, AGTYPEOID, newkeyvals_args, InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); fexpr->location = cm->location; + /* + * If there was a previous concatenation, build a final concatenation + * function node. + */ + if (aa_lhs_arg != NULL) + { + List *aa_args = list_make2(aa_lhs_arg, fexpr); + + fexpr = makeFuncExpr(aa_func_oid, AGTYPEOID, aa_args, InvalidOid, + InvalidOid, COERCE_EXPLICIT_CALL); + } + return (Node *)fexpr; } /* * Helper function to transform a cypher list into an agtype list. The function - * will use agtype_add to concatenate lists when the number of parameters - * exceeds 100, a PG limitation. + * will use agtype_add to concatenate argument lists when the number of list + * elements, parameters, exceeds 100, a PG limitation. */ static Node *transform_cypher_list(cypher_parsestate *cpstate, cypher_list *cl) { @@ -1947,4 +2031,4 @@ static Node *transform_cypher_list_comprehension(cypher_parsestate *cpstate, pstate->p_lateral_active = false; return expr; -} \ No newline at end of file +}