From 3fde055c19795950d307f07194d9b66044956532 Mon Sep 17 00:00:00 2001 From: Pratik Joseph Dabre Date: Thu, 26 Sep 2024 17:47:32 -0700 Subject: [PATCH] Fix protocol errors --- .../presto_protocol/presto_protocol.cpp | 221 +++++++++++++++++- .../presto_protocol/presto_protocol.h | 24 ++ .../presto_protocol/special/Language.cpp.inc | 1 - 3 files changed, 241 insertions(+), 5 deletions(-) diff --git a/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp b/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp index ec0e141784dda..c0d9337ab3938 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp +++ b/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.cpp @@ -72,6 +72,10 @@ void to_json(json& j, const std::shared_ptr& p) { j = *std::static_pointer_cast(p); return; } + if (type == "native") { + j = *std::static_pointer_cast(p); + return; + } throw TypeError(type + " no abstract type FunctionHandle "); } @@ -98,6 +102,13 @@ void from_json(const json& j, std::shared_ptr& p) { p = std::static_pointer_cast(k); return; } + if (type == "native") { + std::shared_ptr k = + std::make_shared(); + j.get_to(*k); + p = std::static_pointer_cast(k); + return; + } throw TypeError(type + " no abstract type FunctionHandle "); } @@ -442,6 +453,43 @@ void from_json(const json& j, Aggregation& p) { } } // namespace facebook::presto::protocol namespace facebook::presto::protocol { + +void to_json(json& j, const AggregationFunctionMetadata& p) { + j = json::object(); + to_json_key( + j, + "intermediateType", + p.intermediateType, + "AggregationFunctionMetadata", + "TypeSignature", + "intermediateType"); + to_json_key( + j, + "isOrderSensitive", + p.isOrderSensitive, + "AggregationFunctionMetadata", + "bool", + "isOrderSensitive"); +} + +void from_json(const json& j, AggregationFunctionMetadata& p) { + from_json_key( + j, + "intermediateType", + p.intermediateType, + "AggregationFunctionMetadata", + "TypeSignature", + "intermediateType"); + from_json_key( + j, + "isOrderSensitive", + p.isOrderSensitive, + "AggregationFunctionMetadata", + "bool", + "isOrderSensitive"); +} +} // namespace facebook::presto::protocol +namespace facebook::presto::protocol { // Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM() // NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays @@ -1458,16 +1506,32 @@ void from_json(const json& j, Determinism& e) { ->first; } } // namespace facebook::presto::protocol +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + namespace facebook::presto::protocol { void to_json(json& j, const Language& p) { - j = json::object(); - to_json_key(j, "language", p.language, "Language", "String", "language"); + json tj = json::object(); + to_json_key(tj, "language", p.language, "Language", "String", "language"); + j = tj["language"]; } void from_json(const json& j, Language& p) { from_json_key(j, "language", p.language, "Language", "String", "language"); } + } // namespace facebook::presto::protocol namespace facebook::presto::protocol { // Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM() @@ -1797,6 +1861,13 @@ void to_json(json& j, const SqlInvokedFunction& p) { "RoutineCharacteristics", "routineCharacteristics"); to_json_key(j, "body", p.body, "SqlInvokedFunction", "String", "body"); + to_json_key( + j, + "variableArity", + p.variableArity, + "SqlInvokedFunction", + "bool", + "variableArity"); to_json_key( j, "signature", @@ -1836,6 +1907,13 @@ void from_json(const json& j, SqlInvokedFunction& p) { "RoutineCharacteristics", "routineCharacteristics"); from_json_key(j, "body", p.body, "SqlInvokedFunction", "String", "body"); + from_json_key( + j, + "variableArity", + p.variableArity, + "SqlInvokedFunction", + "bool", + "variableArity"); from_json_key( j, "signature", @@ -8782,6 +8860,141 @@ void from_json(const json& j, JoinNodeStatsEstimate& p) { "joinProbeKeyCount"); } } // namespace facebook::presto::protocol +namespace facebook::presto::protocol { + +void to_json(json& j, const JsonBasedUdfFunctionMetadata& p) { + j = json::object(); + to_json_key( + j, + "docString", + p.docString, + "JsonBasedUdfFunctionMetadata", + "String", + "docString"); + to_json_key( + j, + "functionKind", + p.functionKind, + "JsonBasedUdfFunctionMetadata", + "FunctionKind", + "functionKind"); + to_json_key( + j, + "outputType", + p.outputType, + "JsonBasedUdfFunctionMetadata", + "TypeSignature", + "outputType"); + to_json_key( + j, + "paramTypes", + p.paramTypes, + "JsonBasedUdfFunctionMetadata", + "List", + "paramTypes"); + to_json_key( + j, + "schema", + p.schema, + "JsonBasedUdfFunctionMetadata", + "String", + "schema"); + to_json_key( + j, + "variableArity", + p.variableArity, + "JsonBasedUdfFunctionMetadata", + "bool", + "variableArity"); + to_json_key( + j, + "routineCharacteristics", + p.routineCharacteristics, + "JsonBasedUdfFunctionMetadata", + "RoutineCharacteristics", + "routineCharacteristics"); + to_json_key( + j, + "aggregateMetadata", + p.aggregateMetadata, + "JsonBasedUdfFunctionMetadata", + "AggregationFunctionMetadata", + "aggregateMetadata"); + to_json_key( + j, + "typeVariableConstraints", + p.typeVariableConstraints, + "JsonBasedUdfFunctionMetadata", + "List", + "typeVariableConstraints"); +} + +void from_json(const json& j, JsonBasedUdfFunctionMetadata& p) { + from_json_key( + j, + "docString", + p.docString, + "JsonBasedUdfFunctionMetadata", + "String", + "docString"); + from_json_key( + j, + "functionKind", + p.functionKind, + "JsonBasedUdfFunctionMetadata", + "FunctionKind", + "functionKind"); + from_json_key( + j, + "outputType", + p.outputType, + "JsonBasedUdfFunctionMetadata", + "TypeSignature", + "outputType"); + from_json_key( + j, + "paramTypes", + p.paramTypes, + "JsonBasedUdfFunctionMetadata", + "List", + "paramTypes"); + from_json_key( + j, + "schema", + p.schema, + "JsonBasedUdfFunctionMetadata", + "String", + "schema"); + from_json_key( + j, + "variableArity", + p.variableArity, + "JsonBasedUdfFunctionMetadata", + "bool", + "variableArity"); + from_json_key( + j, + "routineCharacteristics", + p.routineCharacteristics, + "JsonBasedUdfFunctionMetadata", + "RoutineCharacteristics", + "routineCharacteristics"); + from_json_key( + j, + "aggregateMetadata", + p.aggregateMetadata, + "JsonBasedUdfFunctionMetadata", + "AggregationFunctionMetadata", + "aggregateMetadata"); + from_json_key( + j, + "typeVariableConstraints", + p.typeVariableConstraints, + "JsonBasedUdfFunctionMetadata", + "List", + "typeVariableConstraints"); +} +} // namespace facebook::presto::protocol /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -11623,12 +11836,12 @@ void from_json(const json& j, Specification& p) { } // namespace facebook::presto::protocol namespace facebook::presto::protocol { SqlFunctionHandle::SqlFunctionHandle() noexcept { - _type = "json_file"; + _type = "native"; } void to_json(json& j, const SqlFunctionHandle& p) { j = json::object(); - j["@type"] = "json_file"; + j["@type"] = "native"; to_json_key( j, "functionId", diff --git a/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.h b/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.h index e6c1e36e8b6c2..f34e81694e8d2 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.h +++ b/presto-native-execution/presto_cpp/presto_protocol/presto_protocol.h @@ -439,6 +439,14 @@ void to_json(json& j, const Aggregation& p); void from_json(const json& j, Aggregation& p); } // namespace facebook::presto::protocol namespace facebook::presto::protocol { +struct AggregationFunctionMetadata { + TypeSignature intermediateType = {}; + bool isOrderSensitive = {}; +}; +void to_json(json& j, const AggregationFunctionMetadata& p); +void from_json(const json& j, AggregationFunctionMetadata& p); +} // namespace facebook::presto::protocol +namespace facebook::presto::protocol { enum class AggregationNodeStep { PARTIAL, FINAL, INTERMEDIATE, SINGLE }; extern void to_json(json& j, const AggregationNodeStep& e); extern void from_json(const json& j, AggregationNodeStep& e); @@ -716,6 +724,7 @@ struct SqlInvokedFunction { String description = {}; RoutineCharacteristics routineCharacteristics = {}; String body = {}; + bool variableArity = {}; Signature signature = {}; SqlFunctionId functionId = {}; }; @@ -2259,6 +2268,21 @@ void to_json(json& j, const JoinNodeStatsEstimate& p); void from_json(const json& j, JoinNodeStatsEstimate& p); } // namespace facebook::presto::protocol namespace facebook::presto::protocol { +struct JsonBasedUdfFunctionMetadata { + String docString = {}; + FunctionKind functionKind = {}; + TypeSignature outputType = {}; + List paramTypes = {}; + String schema = {}; + bool variableArity = {}; + RoutineCharacteristics routineCharacteristics = {}; + std::shared_ptr aggregateMetadata = {}; + std::shared_ptr> typeVariableConstraints = {}; +}; +void to_json(json& j, const JsonBasedUdfFunctionMetadata& p); +void from_json(const json& j, JsonBasedUdfFunctionMetadata& p); +} // namespace facebook::presto::protocol +namespace facebook::presto::protocol { struct LambdaDefinitionExpression : public RowExpression { List argumentTypes = {}; List arguments = {}; diff --git a/presto-native-execution/presto_cpp/presto_protocol/special/Language.cpp.inc b/presto-native-execution/presto_cpp/presto_protocol/special/Language.cpp.inc index 1413f38fc3f70..da1c8172869c6 100644 --- a/presto-native-execution/presto_cpp/presto_protocol/special/Language.cpp.inc +++ b/presto-native-execution/presto_cpp/presto_protocol/special/Language.cpp.inc @@ -25,4 +25,3 @@ void from_json(const json& j, Language& p) { } } // namespace facebook::presto::protocol - \ No newline at end of file