Skip to content

Commit e5d1146

Browse files
pramodsatyaaditi-pandit
authored andcommitted
[native] Serialize session property metadata with protocol
1 parent 9394114 commit e5d1146

File tree

3 files changed

+28
-66
lines changed

3 files changed

+28
-66
lines changed

presto-native-execution/presto_cpp/main/SessionProperties.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ const std::string boolToString(bool value) {
2424
}
2525
} // namespace
2626

27-
json SessionProperty::serialize() {
28-
json j;
29-
j["name"] = name_;
30-
j["description"] = description_;
31-
j["typeSignature"] = type_;
32-
j["defaultValue"] = defaultValue_;
33-
j["hidden"] = hidden_;
34-
return j;
35-
}
36-
3727
SessionProperties* SessionProperties::instance() {
3828
static std::unique_ptr<SessionProperties> instance =
3929
std::make_unique<SessionProperties>();
@@ -553,22 +543,18 @@ SessionProperties::SessionProperties() {
553543
std::to_string(c.unnestSplitOutput()));
554544
}
555545

556-
const std::unordered_map<std::string, std::shared_ptr<SessionProperty>>&
557-
SessionProperties::testingSessionProperties() const {
558-
return sessionProperties_;
559-
}
560-
561546
const std::string SessionProperties::toVeloxConfig(
562547
const std::string& name) const {
563548
auto it = sessionProperties_.find(name);
564-
return it == sessionProperties_.end() ? name
565-
: it->second->getVeloxConfigName();
549+
return it == sessionProperties_.end() ? name : it->second->getVeloxConfig();
566550
}
567551

568552
json SessionProperties::serialize() const {
569553
json j = json::array();
570-
for (const auto& entry : sessionProperties_) {
571-
j.push_back(entry.second->serialize());
554+
json tj;
555+
for (const auto& sessionProperty : sessionProperties_) {
556+
protocol::to_json(tj, sessionProperty.second->getMetadata());
557+
j.push_back(tj);
572558
}
573559
return j;
574560
}

presto-native-execution/presto_cpp/main/SessionProperties.h

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma once
1515

1616
#include "presto_cpp/external/json/nlohmann/json.hpp"
17+
#include "presto_cpp/presto_protocol/core/presto_protocol_core.h"
1718
#include "velox/type/Type.h"
1819

1920
using json = nlohmann::json;
@@ -27,44 +28,39 @@ class SessionProperty {
2728
SessionProperty(
2829
const std::string& name,
2930
const std::string& description,
30-
const std::string& type,
31+
const std::string& typeSignature,
3132
bool hidden,
32-
const std::string& veloxConfigName,
33+
const std::string& veloxConfig,
3334
const std::string& defaultValue)
34-
: name_(name),
35-
description_(description),
36-
type_(type),
37-
hidden_(hidden),
38-
veloxConfigName_(veloxConfigName),
39-
defaultValue_(defaultValue),
35+
: metadata_({name, description, typeSignature, defaultValue, hidden}),
36+
veloxConfig_(veloxConfig),
4037
value_(defaultValue) {}
4138

42-
const std::string getVeloxConfigName() {
43-
return veloxConfigName_;
39+
const protocol::SessionPropertyMetadata getMetadata() {
40+
return metadata_;
41+
}
42+
43+
const std::string getVeloxConfig() {
44+
return veloxConfig_;
4445
}
4546

4647
void updateValue(const std::string& value) {
4748
value_ = value;
4849
}
4950

5051
bool operator==(const SessionProperty& other) const {
51-
return name_ == other.name_ && description_ == other.description_ &&
52-
type_ == other.type_ && hidden_ == other.hidden_ &&
53-
veloxConfigName_ == other.veloxConfigName_ &&
54-
defaultValue_ == other.defaultValue_;
52+
const auto otherMetadata = other.metadata_;
53+
return metadata_.name == otherMetadata.name &&
54+
metadata_.description == otherMetadata.description &&
55+
metadata_.typeSignature == otherMetadata.typeSignature &&
56+
metadata_.hidden == otherMetadata.hidden &&
57+
metadata_.defaultValue == otherMetadata.defaultValue &&
58+
veloxConfig_ == other.veloxConfig_;
5559
}
5660

57-
json serialize();
58-
5961
private:
60-
const std::string name_;
61-
const std::string description_;
62-
63-
// Datatype of presto native property.
64-
const std::string type_;
65-
const bool hidden_;
66-
const std::string veloxConfigName_;
67-
const std::string defaultValue_;
62+
const protocol::SessionPropertyMetadata metadata_;
63+
const std::string veloxConfig_;
6864
std::string value_;
6965
};
7066

@@ -354,9 +350,6 @@ class SessionProperties {
354350

355351
json serialize() const;
356352

357-
const std::unordered_map<std::string, std::shared_ptr<SessionProperty>>&
358-
testingSessionProperties() const;
359-
360353
private:
361354
void addSessionProperty(
362355
const std::string& name,

presto-native-execution/presto_cpp/main/tests/SessionPropertiesTest.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,9 @@ TEST_F(SessionPropertiesTest, validateMapping) {
127127
{SessionProperties::kUnnestSplitOutput,
128128
core::QueryConfig::kUnnestSplitOutput}};
129129

130-
const auto& sessionProperties =
131-
SessionProperties::instance()->testingSessionProperties();
132-
133-
ASSERT_EQ(expectedMappings.size(), sessionProperties.size());
134-
135-
for (const auto& [sessionPropertyName, expectedVeloxConfigName] :
136-
expectedMappings) {
130+
const auto sessionProperties = SessionProperties::instance();
131+
for (const auto& [sessionProperty, expectedVeloxConfig] : expectedMappings) {
137132
ASSERT_EQ(
138-
expectedVeloxConfigName,
139-
sessionProperties.at(sessionPropertyName)->getVeloxConfigName());
140-
}
141-
}
142-
143-
TEST_F(SessionPropertiesTest, serializeProperty) {
144-
auto* sessionProperties = SessionProperties::instance();
145-
auto j = sessionProperties->serialize();
146-
for (const auto& property : j) {
147-
auto name = property["name"];
148-
json expectedProperty =
149-
sessionProperties->testingSessionProperties().at(name)->serialize();
150-
EXPECT_EQ(property, expectedProperty);
133+
expectedVeloxConfig, sessionProperties->toVeloxConfig(sessionProperty));
151134
}
152135
}

0 commit comments

Comments
 (0)