Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

[JIT] map function with tuple input #353

Closed
mihaibudiu opened this issue Apr 3, 2023 · 7 comments
Closed

[JIT] map function with tuple input #353

mihaibudiu opened this issue Apr 3, 2023 · 7 comments
Assignees

Comments

@mihaibudiu
Copy link

The JIT validator does not like the implementation of this Rust function:

move |kv: (&(), &Tuple1<Option<F64>>, ), | -> Tuple1<Option<F64>> {
    Tuple1::new(kv.1.0)
}

The code I generate for the JIT has a map function with 2 inputs, one for () and one for the Tuple1, but the JIT code validator reports:
invalid value: map, expected map with a single key at line 536 column 1

This function shows up as part of the aggregate implementations. In general GROUP-BY+AGGREGATE will have a non-empty tuple for the first component of the map function.

@mihaibudiu
Copy link
Author

In fact, I realize that "map" is not really "Map", so the problem is probably elsewhere. Probably the error comes from the serde.

@Kixiron
Copy link
Contributor

Kixiron commented Apr 3, 2023

What does the json look like

@mihaibudiu
Copy link
Author

{
  "nodes" : {
    "79" : {
      "Source" : {
        "layout" : 1
      }
    },
    "271" : {
      "Map" : {
        "input" : 79,
        "map_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 1,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 2,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 3, {
                "Load" : {
                  "source" : 1,
                  "source_layout" : 3,
                  "column" : 1,
                  "column_type" : "F64"
                }
              } ], [ 4, {
                "Store" : {
                  "target" : 2,
                  "target_layout" : 2,
                  "column" : 0,
                  "value" : {
                    "Expr" : 3
                  },
                  "value_type" : "F64"
                }
              } ] ],
              "terminator" : {
                "Return" : {
                  "value" : {
                    "Imm" : "Unit"
                  }
                }
              }
            }
          }
        },
        "layout" : 2
      }
    },
    "280" : {
      "IndexWith" : {
        "input" : 271,
        "index_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 2,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 4,
            "flags" : "output"
          }, {
            "id" : 3,
            "layout" : 2,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 4, {
                "Load" : {
                  "source" : 1,
                  "source_layout" : 5,
                  "column" : 0,
                  "column_type" : "F64"
                }
              } ], [ 5, {
                "Store" : {
                  "target" : 3,
                  "target_layout" : 2,
                  "column" : 0,
                  "value" : {
                    "Expr" : 4
                  },
                  "value_type" : "F64"
                }
              } ] ],
              "terminator" : {
                "Return" : {
                  "value" : {
                    "Imm" : "Unit"
                  }
                }
              }
            }
          }
        },
        "key_layout" : 6,
        "value_layout" : 2
      }
    },
    "282" : {
      "Fold" : {
        "input" : 280,
        "init" : {
          "rows" : [ {
            "Nullable" : null
          } ]
        },
        "step_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 7,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 2,
            "flags" : "input"
          }, {
            "id" : 3,
            "layout" : 8,
            "flags" : "input"
          }, {
            "id" : 4,
            "layout" : 7,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 6, {
                "Load" : {
                  "source" : 5,
                  "source_layout" : 9,
                  "column" : 0,
                  "column_type" : "I64"
                }
              } ], [ 9, {
                "Load" : {
                  "source" : 1,
                  "source_layout" : 7,
                  "column" : 0,
                  "column_type" : "F64"
                }
              } ], [ 10, {
                "IsNull" : {
                  "target" : 1,
                  "target_layout" : 7,
                  "column" : 0
                }
              } ], [ 11, {
                "Load" : {
                  "source" : 2,
                  "source_layout" : 5,
                  "column" : 0,
                  "column_type" : "F64"
                }
              } ], [ 12, {
                "Constant" : {
                  "Bool" : false
                }
              } ], [ 13, {
                "BinOp" : {
                  "lhs" : 11,
                  "rhs" : 5,
                  "kind" : "Mul",
                  "operand_ty" : "F64"
                }
              } ], [ 14, {
                "Constant" : {
                  "Bool" : false
                }
              } ], [ 15, {
                "BinOp" : {
                  "lhs" : 9,
                  "rhs" : 13,
                  "kind" : "Add",
                  "operand_ty" : "F64"
                }
              } ], [ 16, {
                "BinOp" : {
                  "lhs" : 10,
                  "rhs" : 14,
                  "kind" : "And",
                  "operand_ty" : "Bool"
                }
              } ], [ 17, {
                "Store" : {
                  "target" : 4,
                  "target_layout" : 7,
                  "column" : 0,
                  "value" : {
                    "Expr" : 7
                  },
                  "value_type" : "F64"
                }
              } ], [ 18, {
                "SetNull" : {
                  "target" : 4,
                  "target_layout" : 7,
                  "column" : 0,
                  "is_null" : {
                    "Expr" : 8
                  }
                }
              } ] ],
              "terminator" : {
                "Return" : {
                  "value" : {
                    "Imm" : "Unit"
                  }
                }
              }
            }
          }
        },
        "finish_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 7,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 7,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 5, {
                "Load" : {
                  "source" : 1,
                  "source_layout" : 7,
                  "column" : 0,
                  "column_type" : "F64"
                }
              } ], [ 6, {
                "IsNull" : {
                  "target" : 1,
                  "target_layout" : 7,
                  "column" : 0
                }
              } ], [ 7, {
                "Store" : {
                  "target" : 2,
                  "target_layout" : 7,
                  "column" : 0,
                  "value" : {
                    "Expr" : 3
                  },
                  "value_type" : "F64"
                }
              } ], [ 8, {
                "SetNull" : {
                  "target" : 2,
                  "target_layout" : 7,
                  "column" : 0,
                  "is_null" : {
                    "Expr" : 4
                  }
                }
              } ] ],
              "terminator" : {
                "Return" : {
                  "value" : {
                    "Imm" : "Unit"
                  }
                }
              }
            }
          }
        },
        "acc_layout" : 7,
        "step_layout" : 7,
        "output_layout" : 7
      }
    },
    "293" : {
      "Map" : {
        "input" : 282,
        "map_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 4,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 7,
            "flags" : "input"
          }, {
            "id" : 3,
            "layout" : 7,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 4, {
                "Load" : {
                  "source" : 2,
                  "source_layout" : 10,
                  "column" : 0,
                  "column_type" : "F64"
                }
              } ], [ 5, {
                "IsNull" : {
                  "target" : 2,
                  "target_layout" : 10,
                  "column" : 0
                }
              } ], [ 6, {
                "Store" : {
                  "target" : 3,
                  "target_layout" : 7,
                  "column" : 0,
                  "value" : {
                    "Expr" : 4
                  },
                  "value_type" : "F64"
                }
              } ], [ 7, {
                "SetNull" : {
                  "target" : 3,
                  "target_layout" : 7,
                  "column" : 0,
                  "is_null" : {
                    "Expr" : 5
                  }
                }
              } ] ],
              "terminator" : {
                "Return" : {
                  "value" : {
                    "Imm" : "Unit"
                  }
                }
              }
            }
          }
        },
        "layout" : 7
      }
    },
    "306" : {
      "Map" : {
        "input" : 293,
        "map_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 7,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 7,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 3, { } ], [ 4, {
                "Constant" : {
                  "is_null" : true
                }
              } ], [ 5, {
                "Store" : {
                  "target" : 2,
                  "target_layout" : 7,
                  "column" : 0,
                  "value" : {
                    "Expr" : 3
                  },
                  "value_type" : "F64"
                }
              } ], [ 6, {
                "SetNull" : {
                  "target" : 2,
                  "target_layout" : 7,
                  "column" : 0,
                  "is_null" : {
                    "Expr" : 4
                  }
                }
              } ] ],
              "terminator" : {
                "Return" : {
                  "value" : {
                    "Imm" : "Unit"
                  }
                }
              }
            }
          }
        },
        "layout" : 7
      }
    },
    "308" : {
      "Neg" : {
        "input" : 306
      }
    },
    "309" : {
      "Constant" : {
        "layout" : {
          "Set" : 7
        },
        "value" : {
          "Set" : [ [ {
            "rows" : [ {
              "Nullable" : null
            } ]
          }, 1 ] ]
        }
      }
    },
    "310" : {
      "Sum" : {
        "inputs" : [ 309, 308, 293 ]
      }
    },
    "311" : {
      "Sink" : {
        "input" : 310
      }
    }
  },
  "layouts" : {
    "4" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "Unit"
      } ]
    },
    "6" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "Unit"
      } ]
    },
    "10" : {
      "columns" : [ {
        "nullable" : true,
        "ty" : "F64"
      } ]
    },
    "1" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "I32"
      }, {
        "nullable" : false,
        "ty" : "F64"
      }, {
        "nullable" : false,
        "ty" : "Bool"
      }, {
        "nullable" : false,
        "ty" : "String"
      }, {
        "nullable" : true,
        "ty" : "I32"
      }, {
        "nullable" : true,
        "ty" : "F64"
      } ]
    },
    "7" : {
      "columns" : [ {
        "nullable" : true,
        "ty" : "F64"
      } ]
    },
    "3" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "I32"
      }, {
        "nullable" : false,
        "ty" : "F64"
      }, {
        "nullable" : false,
        "ty" : "Bool"
      }, {
        "nullable" : false,
        "ty" : "String"
      }, {
        "nullable" : true,
        "ty" : "I32"
      }, {
        "nullable" : true,
        "ty" : "F64"
      } ]
    },
    "2" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "F64"
      } ]
    },
    "5" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "F64"
      } ]
    },
    "8" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "I64"
      } ]
    },
    "9" : {
      "columns" : [ {
        "nullable" : false,
        "ty" : "I64"
      } ]
    }
  }
}

@mihaibudiu
Copy link
Author

Having a fix to #349 would allow me to debug this myself

@Kixiron
Copy link
Contributor

Kixiron commented Apr 4, 2023

Yah I'm looking into that, it's something funky to do with serde

@Kixiron
Copy link
Contributor

Kixiron commented Apr 6, 2023

Found the issue, [ 3, { } ], isn't a valid expression

    "306" : {
      "Map" : {
        "input" : 293,
        "map_fn" : {
          "args" : [ {
            "id" : 1,
            "layout" : 7,
            "flags" : "input"
          }, {
            "id" : 2,
            "layout" : 7,
            "flags" : "output"
          } ],
          "ret" : "Unit",
          "entry_block" : 1,
          "blocks" : {
            "1" : {
              "id" : 1,
              "body" : [ [ 3, { } ], [ 4, {
                "Constant" : {
                  "is_null" : true
                }
              } ], [ 5, {

additionally "Constant" : { "is_null" : true } isn't a valid constant, if you want a null value you should just be able to use a false for a null flag

@mihaibudiu
Copy link
Author

I will add some validation for this case myself. I think empty objects never make sense for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants