Skip to content

Commit ad2b2a0

Browse files
pdabre12xin-zhang2
authored andcommitted
Made some changes
1 parent 0ea1ef0 commit ad2b2a0

File tree

17 files changed

+233
-132
lines changed

17 files changed

+233
-132
lines changed

presto-main-base/src/main/java/com/facebook/presto/metadata/FunctionAndTypeManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
import static com.facebook.presto.metadata.FunctionSignatureMatcher.constructFunctionNotFoundErrorMessage;
108108
import static com.facebook.presto.metadata.SessionFunctionHandle.SESSION_NAMESPACE;
109109
import static com.facebook.presto.metadata.SignatureBinder.applyBoundVariables;
110-
import static com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS;
111110
import static com.facebook.presto.metadata.TableFunctionRegistry.toPath;
111+
import static com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS;
112112
import static com.facebook.presto.spi.StandardErrorCode.FUNCTION_IMPLEMENTATION_MISSING;
113113
import static com.facebook.presto.spi.StandardErrorCode.FUNCTION_NOT_FOUND;
114114
import static com.facebook.presto.spi.StandardErrorCode.GENERIC_USER_ERROR;
@@ -494,9 +494,9 @@ public TableFunctionMetadata resolveTableFunction(Session session, QualifiedName
494494
.qualifyObjectName(qualifiedName).getObjectName());
495495
if (tableFunctionMetadata == null) {
496496
// populate the registry before trying to resolve the table functions from table functions provider
497-
CatalogSchemaFunctionName name = toPath(session, qualifiedName);
498-
ConnectorId connectorId = new ConnectorId(name.getCatalogName());
499-
return tableFunctionRegistry.resolve(connectorId, name);
497+
List<CatalogSchemaFunctionName> name = toPath(session, qualifiedName);
498+
ConnectorId connectorId = new ConnectorId(name.get(0).getCatalogName());
499+
return tableFunctionRegistry.resolve(connectorId, name.get(0));
500500
}
501501
return tableFunctionMetadata;
502502
}

presto-main-base/src/main/java/com/facebook/presto/operator/table/ExcludeColumns.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import static com.facebook.presto.spi.StandardErrorCode.INVALID_ARGUMENTS;
4343
import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
4444
import static com.facebook.presto.spi.function.table.DescriptorArgument.NULL_DESCRIPTOR;
45-
import static com.facebook.presto.spi.function.table.ReturnTypeSpecification.GenericTable.GENERIC_TABLE;
45+
import static com.facebook.presto.spi.function.table.GenericTableReturnTypeSpecification.GENERIC_TABLE;
4646
import static com.facebook.presto.spi.function.table.TableFunctionProcessorState.Finished.FINISHED;
4747
import static com.facebook.presto.spi.function.table.TableFunctionProcessorState.Processed.usedInputAndProduced;
4848
import static com.google.common.collect.ImmutableSet.toImmutableSet;

presto-main-base/src/main/java/com/facebook/presto/operator/table/Sequence.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.facebook.presto.spi.function.table.Argument;
2828
import com.facebook.presto.spi.function.table.ConnectorTableFunction;
2929
import com.facebook.presto.spi.function.table.ConnectorTableFunctionHandle;
30-
import com.facebook.presto.spi.function.table.ReturnTypeSpecification.DescribedTable;
30+
import com.facebook.presto.spi.function.table.DescribedTableReturnTypeSpecification;
3131
import com.facebook.presto.spi.function.table.ScalarArgument;
3232
import com.facebook.presto.spi.function.table.ScalarArgumentSpecification;
3333
import com.facebook.presto.spi.function.table.TableFunctionAnalysis;
@@ -96,7 +96,7 @@ public SequenceFunction()
9696
.type(BIGINT)
9797
.defaultValue(1L)
9898
.build()),
99-
new DescribedTable(descriptor(ImmutableList.of("sequential_number"), ImmutableList.of(BIGINT))));
99+
new DescribedTableReturnTypeSpecification(descriptor(ImmutableList.of("sequential_number"), ImmutableList.of(BIGINT))));
100100
}
101101

102102
@Override

presto-main/src/main/java/com/facebook/presto/server/PrestoServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.facebook.presto.metadata.Catalog;
4444
import com.facebook.presto.metadata.CatalogManager;
4545
import com.facebook.presto.metadata.DiscoveryNodeManager;
46+
import com.facebook.presto.metadata.FunctionAndTypeManager;
4647
import com.facebook.presto.metadata.InternalNodeManager;
4748
import com.facebook.presto.metadata.SessionPropertyManager;
4849
import com.facebook.presto.metadata.StaticCatalogStore;

presto-native-execution/presto_cpp/main/CMakeLists.txt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,7 @@ endif()
102102
target_link_libraries(presto_server_lib presto_thrift-cpp2 presto_thrift_extra
103103
${THRIFT_LIBRARY})
104104

105-
set_property(TARGET presto_server_lib PROPERTY JOB_POOL_LINK
106-
presto_link_job_pool)
107-
108-
add_executable(presto_server PrestoMain.cpp)
109-
110-
# Moving velox_hive_connector and velox_tpch_connector to presto_server_lib
111-
# results in multiple link errors similar to the one below only on GCC.
112-
# "undefined reference to `vtable for velox::connector::tpch::TpchTableHandle`"
113-
# TODO: Fix these errors.
114-
target_link_libraries(presto_server presto_server_lib velox_hive_connector
115-
velox_tpch_connector)
116-
117-
# Clang requires explicit linking with libatomic.
118-
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
119-
AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL 15)
120-
target_link_libraries(presto_server atomic)
121-
endif()
122-
123-
# if(PRESTO_ENABLE_TABLE_FUNCTIONS) add_subdirectory(tvf)
105+
# if(PRESTO_ENABLE_TABLE_FUNCTIONS) add_subdirectory(tvf)
124106
add_subdirectory(tvf)
125107
target_link_libraries(presto_server_lib presto_tvf_exec presto_tvf_functions)
126108
# endif()
@@ -137,6 +119,8 @@ endif()
137119
set_property(TARGET presto_server_lib PROPERTY JOB_POOL_LINK
138120
presto_link_job_pool)
139121

122+
add_executable(presto_server PrestoMain.cpp)
123+
140124
# The below additional flags are necessary for resolving dependencies for
141125
# loading dynamic libraries.
142126
if(APPLE)

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
#include <pthread.h>
8585
#include <sched.h>
8686
#endif
87+
#include <iostream>
8788

8889
using namespace facebook;
8990

@@ -397,9 +398,33 @@ void PrestoServer::run() {
397398
const std::vector<std::unique_ptr<folly::IOBuf>>& body,
398399
proxygen::ResponseHandler* downstream) {
399400
std::string connectorTableMetadataJson = util::extractMessageBody(body);
400-
// protocol::ConnectorTableMetadata connectorTableMetadata;
401-
// protocol::from_json(json(connectorTableMetadataJson), connectorTableMetadata);
402-
http::sendOkResponse(downstream, json("response"));
401+
402+
try {
403+
protocol::ConnectorTableMetadata1 connectorTableMetadata;
404+
protocol::from_json(json::parse(connectorTableMetadataJson), connectorTableMetadata);
405+
std::unordered_map<std::string, std::shared_ptr<tvf::Argument>> args;
406+
for (const auto& entry : connectorTableMetadata.arguments) {
407+
std::shared_ptr<tvf::Argument> arg;
408+
if (auto scalarArgument = std::dynamic_pointer_cast<protocol::ScalarArgument>(entry.second)) {
409+
auto serializableNullableValue = scalarArgument->nullableValue.serializable;
410+
arg = std::make_shared<tvf::ScalarArgument>(
411+
serializableNullableValue.type, serializableNullableValue.block);
412+
}
413+
else if (auto tableArgument = std::dynamic_pointer_cast<protocol::TableArgument>(entry.second)) {
414+
arg = std::make_shared<tvf::TableArgument>(tableArgument->rowType);
415+
}
416+
else if (std::dynamic_pointer_cast<protocol::DescriptorArgument>(entry.second)) {
417+
}
418+
else {
419+
VELOX_FAIL("Failed to convert to a valid Argument");
420+
}
421+
args[entry.first] = arg;
422+
}
423+
tvf::TableFunction::analyze(connectorTableMetadata.name, args);
424+
} catch(const std::exception& e) {
425+
std::cerr << "JSON type error: " << e.what() << std::endl;
426+
};
427+
http::sendOkResponse(downstream, json("response"));
403428
});
404429

405430
if (systemConfig->enableRuntimeMetricsCollection()) {
@@ -1335,12 +1360,6 @@ void PrestoServer::registerFunctions() {
13351360
prestoBuiltinFunctionPrefix_);
13361361
velox::window::prestosql::registerAllWindowFunctions(
13371362
prestoBuiltinFunctionPrefix_);
1338-
if (SystemConfig::instance()->registerTestFunctions()) {
1339-
velox::functions::prestosql::registerAllScalarFunctions(
1340-
"json.test_schema.");
1341-
velox::aggregate::prestosql::registerAllAggregateFunctions(
1342-
"json.test_schema.");
1343-
}
13441363

13451364
// #ifdef PRESTO_ENABLE_TABLE_FUNCTIONS
13461365
velox::exec::Operator::registerOperator(

presto-native-execution/presto_cpp/main/types/FunctionMetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ protocol::Descriptor buildDescriptor(const Descriptor& descriptor) {
275275
std::shared_ptr<std::string> type = (i < types.size())
276276
? std::make_shared<std::string>(types.at(i)->toString())
277277
: nullptr;
278-
fields.emplace_back(protocol::Field{names[i], type});
278+
fields.emplace_back(protocol::Field{std::make_shared<std::string>(names.at(i)), type});
279279
}
280280
return protocol::Descriptor{fields};
281281
}

presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.cpp

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,10 @@ void to_json(json& j, const std::shared_ptr<Argument>& p) {
30613061
j = *std::static_pointer_cast<DescriptorArgument>(p);
30623062
return;
30633063
}
3064+
if (type == "scalar") {
3065+
j = *std::static_pointer_cast<ScalarArgument>(p);
3066+
return;
3067+
}
30643068
if (type == "table") {
30653069
j = *std::static_pointer_cast<TableArgument>(p);
30663070
return;
@@ -3084,6 +3088,12 @@ void from_json(const json& j, std::shared_ptr<Argument>& p) {
30843088
p = std::static_pointer_cast<Argument>(k);
30853089
return;
30863090
}
3091+
if (type == "scalar") {
3092+
std::shared_ptr<ScalarArgument> k = std::make_shared<ScalarArgument>();
3093+
j.get_to(*k);
3094+
p = std::static_pointer_cast<Argument>(k);
3095+
return;
3096+
}
30873097
if (type == "table") {
30883098
std::shared_ptr<TableArgument> k = std::make_shared<TableArgument>();
30893099
j.get_to(*k);
@@ -3104,7 +3114,7 @@ void to_json(json& j, const ConnectorTableMetadata1& p) {
31043114
"arguments",
31053115
p.arguments,
31063116
"ConnectorTableMetadata1",
3107-
"Map<String, Argument>",
3117+
"Map<String, std::shared_ptr<Argument>>",
31083118
"arguments");
31093119
}
31103120

@@ -3115,7 +3125,7 @@ void from_json(const json& j, ConnectorTableMetadata1& p) {
31153125
"arguments",
31163126
p.arguments,
31173127
"ConnectorTableMetadata1",
3118-
"Map<String, Argument>",
3128+
"Map<String, std::shared_ptr<Argument>>",
31193129
"arguments");
31203130
}
31213131
} // namespace facebook::presto::protocol
@@ -7565,6 +7575,42 @@ void from_json(const json& j, NodeStatus& p) {
75657575
}
75667576
} // namespace facebook::presto::protocol
75677577
namespace facebook::presto::protocol {
7578+
7579+
void to_json(json& j, const Serializable& p) {
7580+
j = json::object();
7581+
to_json_key(j, "type", p.type, "Serializable", "Type", "type");
7582+
to_json_key(j, "block", p.block, "Serializable", "Block", "block");
7583+
}
7584+
7585+
void from_json(const json& j, Serializable& p) {
7586+
from_json_key(j, "type", p.type, "Serializable", "Type", "type");
7587+
from_json_key(j, "block", p.block, "Serializable", "Block", "block");
7588+
}
7589+
} // namespace facebook::presto::protocol
7590+
namespace facebook::presto::protocol {
7591+
7592+
void to_json(json& j, const NullableValue& p) {
7593+
j = json::object();
7594+
to_json_key(
7595+
j,
7596+
"serializable",
7597+
p.serializable,
7598+
"NullableValue",
7599+
"Serializable",
7600+
"serializable");
7601+
}
7602+
7603+
void from_json(const json& j, NullableValue& p) {
7604+
from_json_key(
7605+
j,
7606+
"serializable",
7607+
p.serializable,
7608+
"NullableValue",
7609+
"Serializable",
7610+
"serializable");
7611+
}
7612+
} // namespace facebook::presto::protocol
7613+
namespace facebook::presto::protocol {
75687614
OnlyPassThroughReturnTypeSpecification::
75697615
OnlyPassThroughReturnTypeSpecification() noexcept {
75707616
_type = "only_pass_through_table";
@@ -9453,6 +9499,34 @@ void from_json(const json& j, SampleNode& p) {
94539499
}
94549500
} // namespace facebook::presto::protocol
94559501
namespace facebook::presto::protocol {
9502+
ScalarArgument::ScalarArgument() noexcept {
9503+
_type = "scalar";
9504+
}
9505+
9506+
void to_json(json& j, const ScalarArgument& p) {
9507+
j = json::object();
9508+
j["@type"] = "scalar";
9509+
to_json_key(
9510+
j,
9511+
"nullableValue",
9512+
p.nullableValue,
9513+
"ScalarArgument",
9514+
"NullableValue",
9515+
"nullableValue");
9516+
}
9517+
9518+
void from_json(const json& j, ScalarArgument& p) {
9519+
p._type = j["@type"];
9520+
from_json_key(
9521+
j,
9522+
"nullableValue",
9523+
p.nullableValue,
9524+
"ScalarArgument",
9525+
"NullableValue",
9526+
"nullableValue");
9527+
}
9528+
} // namespace facebook::presto::protocol
9529+
namespace facebook::presto::protocol {
94569530
// Loosly copied this here from NLOHMANN_JSON_SERIALIZE_ENUM()
94579531

94589532
// NOLINTNEXTLINE: cppcoreguidelines-avoid-c-arrays

presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ void from_json(const json& j, Column& p);
917917
namespace facebook::presto::protocol {
918918
struct ConnectorTableMetadata1 {
919919
String name = {};
920-
Map<String, Argument> arguments = {};
920+
Map<String, std::shared_ptr<Argument>> arguments = {};
921921
};
922922
void to_json(json& j, const ConnectorTableMetadata1& p);
923923
void from_json(const json& j, ConnectorTableMetadata1& p);
@@ -1853,6 +1853,21 @@ void to_json(json& j, const NodeStatus& p);
18531853
void from_json(const json& j, NodeStatus& p);
18541854
} // namespace facebook::presto::protocol
18551855
namespace facebook::presto::protocol {
1856+
struct Serializable {
1857+
Type type = {};
1858+
Block block = {};
1859+
};
1860+
void to_json(json& j, const Serializable& p);
1861+
void from_json(const json& j, Serializable& p);
1862+
} // namespace facebook::presto::protocol
1863+
namespace facebook::presto::protocol {
1864+
struct NullableValue {
1865+
Serializable serializable = {};
1866+
};
1867+
void to_json(json& j, const NullableValue& p);
1868+
void from_json(const json& j, NullableValue& p);
1869+
} // namespace facebook::presto::protocol
1870+
namespace facebook::presto::protocol {
18561871
struct OnlyPassThroughReturnTypeSpecification : public ReturnTypeSpecification {
18571872
String dummy = {};
18581873

@@ -2178,6 +2193,15 @@ void to_json(json& j, const SampleNode& p);
21782193
void from_json(const json& j, SampleNode& p);
21792194
} // namespace facebook::presto::protocol
21802195
namespace facebook::presto::protocol {
2196+
struct ScalarArgument : public Argument {
2197+
NullableValue nullableValue = {};
2198+
2199+
ScalarArgument() noexcept;
2200+
};
2201+
void to_json(json& j, const ScalarArgument& p);
2202+
void from_json(const json& j, ScalarArgument& p);
2203+
} // namespace facebook::presto::protocol
2204+
namespace facebook::presto::protocol {
21812205
enum class DistributionType { PARTITIONED, REPLICATED };
21822206
extern void to_json(json& j, const DistributionType& e);
21832207
extern void from_json(const json& j, DistributionType& e);

presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ AbstractClasses:
214214
- { name: GenericTableReturnTypeSpecification, key: generic_table }
215215
- { name: OnlyPassThroughReturnTypeSpecification, key: only_pass_through_table }
216216

217+
Argument:
218+
super: JsonEncodedSubclass
219+
subclasses:
220+
- { name: DescriptorArgument, key: descriptor }
221+
- { name: ScalarArgument, key: scalar }
222+
- { name: TableArgument, key: table }
217223

218224
JavaClasses:
219225
- presto-spi/src/main/java/com/facebook/presto/spi/ErrorCause.java
@@ -373,3 +379,10 @@ JavaClasses:
373379
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/DescribedTableReturnTypeSpecification.java
374380
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/GenericTableReturnTypeSpecification.java
375381
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/OnlyPassThroughReturnTypeSpecification.java
382+
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/Argument.java
383+
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/DescriptorArgument.java
384+
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/ScalarArgument.java
385+
- presto-spi/src/main/java/com/facebook/presto/spi/function/table/TableArgument.java
386+
- presto-native-tvf/src/main/java/com/facebook/presto/tvf/ConnectorTableMetadata1.java
387+
- presto-common/src/main/java/com/facebook/presto/common/type/RowType.java
388+
- presto-common/src/main/java/com/facebook/presto/common/predicate/NullableValue.java

0 commit comments

Comments
 (0)