| 1619 | } |
| 1620 | |
| 1621 | Result<Expression> GetOne() { |
| 1622 | if (index_ >= metadata().size()) { |
| 1623 | return Status::Invalid("unterminated serialized Expression"); |
| 1624 | } |
| 1625 | |
| 1626 | const std::string& key = metadata().key(index_); |
| 1627 | const std::string& value = metadata().value(index_); |
| 1628 | ++index_; |
| 1629 | |
| 1630 | if (key == "literal") { |
| 1631 | ARROW_ASSIGN_OR_RAISE(auto scalar, GetScalar(value)); |
| 1632 | return literal(std::move(scalar)); |
| 1633 | } |
| 1634 | |
| 1635 | if (key == "nested_field_ref") { |
| 1636 | int32_t size; |
| 1637 | if (!ParseInteger(value, &size)) { |
| 1638 | return Status::Invalid("Couldn't parse nested field ref length"); |
| 1639 | } |
| 1640 | if (size <= 0) { |
| 1641 | return Status::Invalid("nested field ref length must be > 0"); |
| 1642 | } |
| 1643 | std::vector<FieldRef> nested; |
| 1644 | nested.reserve(size); |
| 1645 | while (size-- > 0) { |
| 1646 | ARROW_ASSIGN_OR_RAISE(auto ref, GetOne()); |
| 1647 | if (!ref.field_ref()) { |
| 1648 | return Status::Invalid("invalid nested field ref"); |
| 1649 | } |
| 1650 | nested.push_back(*ref.field_ref()); |
| 1651 | } |
| 1652 | return field_ref(FieldRef(std::move(nested))); |
| 1653 | } |
| 1654 | |
| 1655 | if (key == "field_ref") { |
| 1656 | return field_ref(value); |
| 1657 | } |
| 1658 | |
| 1659 | if (key != "call") { |
| 1660 | return Status::Invalid("Unrecognized serialized Expression key ", key); |
| 1661 | } |
| 1662 | |
| 1663 | std::vector<Expression> arguments; |
| 1664 | while (metadata().key(index_) != "end") { |
| 1665 | if (metadata().key(index_) == "options") { |
| 1666 | ARROW_ASSIGN_OR_RAISE(auto options_scalar, GetScalar(metadata().value(index_))); |
| 1667 | std::shared_ptr<compute::FunctionOptions> options; |
| 1668 | if (options_scalar) { |
| 1669 | ARROW_ASSIGN_OR_RAISE( |
| 1670 | options, internal::FunctionOptionsFromStructScalar( |
| 1671 | checked_cast<const StructScalar&>(*options_scalar))); |
| 1672 | } |
| 1673 | auto expr = call(value, std::move(arguments), std::move(options)); |
| 1674 | index_ += 2; |
| 1675 | return expr; |
| 1676 | } |
| 1677 | |
| 1678 | ARROW_ASSIGN_OR_RAISE(auto argument, GetOne()); |