From 6b54911a6c9c8637873b4839f69a3817e53cda3c Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Thu, 11 Jun 2026 20:32:32 +0200 Subject: [PATCH 01/12] fix(ci): make the Nix build work with NES_ENABLE_MEOS=OFF and stock paho-mqtt-cpp The Nix environment provides paho-mqtt-cpp as a shared-only library and does not include libmeos. Four changes make the build pass: - flake.nix: add stock paho-mqtt-c + paho-mqtt-cpp to baseThirdPartyDeps; pass -DNES_ENABLE_MEOS=OFF in both defaultPackage and devShell cmakeFlags. - nes-plugins/CMakeLists.txt: introduce NES_ENABLE_MQTT and NES_ENABLE_MEOS options that gate the respective plugin subdirectories via activate_optional_plugin(). - nes-plugins/Sources/MQTTSource, nes-plugins/Sinks/MQTTSink: select PahoMqttCpp::paho-mqttpp3-static when available, fall back to the shared PahoMqttCpp::paho-mqttpp3 target (Nix only ships the shared variant). - nes-physical-operators: gate all MEOS-specific add_plugin calls and the nes-meos link behind if(NES_ENABLE_MEOS) in three CMakeLists files (top-level, Functions/Meos, Aggregation/Function/Meos). - CMakeLists.txt (root): declare option(NES_ENABLE_MEOS) and add_compile_definitions(NES_ENABLE_MEOS) before the nes-* subdirectory loop so the preprocessor symbol is visible to all sibling components. - nes-query-optimizer/LowerToPhysicalWindowedAggregation.cpp: guard the TemporalSequenceAggregationPhysicalFunction include and instantiation with #ifdef NES_ENABLE_MEOS so the translation unit compiles and links when MEOS is disabled. --- CMakeLists.txt | 7 +++ flake.nix | 4 ++ nes-physical-operators/CMakeLists.txt | 6 +- .../Aggregation/Function/Meos/CMakeLists.txt | 2 + .../src/Functions/Meos/CMakeLists.txt | 2 + nes-plugins/CMakeLists.txt | 55 ++++++++++--------- nes-plugins/Sinks/MQTTSink/CMakeLists.txt | 9 ++- nes-plugins/Sources/MQTTSource/CMakeLists.txt | 9 ++- .../LowerToPhysicalWindowedAggregation.cpp | 4 ++ 9 files changed, 67 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dcaa97099..c67d32c34d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,13 @@ endif () add_custom_target(build_all_plugins) +# Declared here so add_compile_definitions reaches all sibling nes-* targets. +# nes-plugins/CMakeLists.txt re-declares the same option (no-op when cached). +option(NES_ENABLE_MEOS "Enable MEOS plugin (requires libmeos installed on the system)" ON) +if(NES_ENABLE_MEOS) + add_compile_definitions(NES_ENABLE_MEOS) +endif() + # Add target for common lib, which contains a minimal set # of shared functionality used by all components of nes file(GLOB NES_DIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "nes-*") diff --git a/flake.nix b/flake.nix index 2d9788a4de..026e310022 100644 --- a/flake.nix +++ b/flake.nix @@ -54,6 +54,8 @@ tbb python3 openjdk21 + paho-mqtt-c + paho-mqtt-cpp ]) ++ [ follyPkg antlr4Pkg ]; antlr4Jar = pkgs.fetchurl { @@ -244,6 +246,7 @@ "-DNES_ENABLES_TESTS=ON" "-DCMAKE_MODULE_PATH=${libdwarfModule}/share/cmake/Modules" "-DANTLR4_JAR_LOCATION=${antlr4Jar}" + "-DNES_ENABLE_MEOS=OFF" ]; enableParallelBuilding = true; @@ -347,6 +350,7 @@ "-DLLVM_DIR=${commonCmakeEnv.LLVM_DIR}" "-DANTLR4_JAR_LOCATION=${antlr4Jar}" "-DCMAKE_MODULE_PATH=${libdwarfModule}/share/cmake/Modules" + "-DNES_ENABLE_MEOS=OFF" ]; shellHook = '' unset NES_PREBUILT_VCPKG_ROOT diff --git a/nes-physical-operators/CMakeLists.txt b/nes-physical-operators/CMakeLists.txt index c38afaf4db..b62a5922a9 100644 --- a/nes-physical-operators/CMakeLists.txt +++ b/nes-physical-operators/CMakeLists.txt @@ -19,7 +19,11 @@ get_source(nes-physical-operators NES_PHYSICAL_OPERATORS_SOURCE_FILES) # Add Library add_library(nes-physical-operators ${NES_PHYSICAL_OPERATORS_SOURCE_FILES}) -target_link_libraries(nes-physical-operators PUBLIC nes-sources nes-sinks nes-nautilus nes-meos) +if(NES_ENABLE_MEOS) + target_link_libraries(nes-physical-operators PUBLIC nes-sources nes-sinks nes-nautilus nes-meos) +else() + target_link_libraries(nes-physical-operators PUBLIC nes-sources nes-sinks nes-nautilus) +endif() target_include_directories(nes-physical-operators PUBLIC $ $) diff --git a/nes-physical-operators/src/Aggregation/Function/Meos/CMakeLists.txt b/nes-physical-operators/src/Aggregation/Function/Meos/CMakeLists.txt index c34e12f47e..0b107d5c2a 100644 --- a/nes-physical-operators/src/Aggregation/Function/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Aggregation/Function/Meos/CMakeLists.txt @@ -10,5 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(NES_ENABLE_MEOS) add_plugin(TemporalSequence AggregationPhysicalFunction nes-physical-operators TemporalSequenceAggregationPhysicalFunction.cpp) add_plugin(Var AggregationPhysicalFunction nes-physical-operators VarAggregationFunction.cpp) +endif() diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index 516cdce4c3..cf83ac5aad 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -10,9 +10,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(NES_ENABLE_MEOS) add_plugin(TemporalIntersects PhysicalFunction nes-physical-operators TemporalIntersectsPhysicalFunction.cpp) add_plugin(TemporalIntersectsGeometry PhysicalFunction nes-physical-operators TemporalIntersectsGeometryPhysicalFunction.cpp) add_plugin(TemporalAIntersectsGeometry PhysicalFunction nes-physical-operators TemporalAIntersectsGeometryPhysicalFunction.cpp) add_plugin(TemporalEContainsGeometry PhysicalFunction nes-physical-operators TemporalEContainsGeometryPhysicalFunction.cpp) add_plugin(TemporalEDWithinGeometry PhysicalFunction nes-physical-operators TemporalEDWithinGeometryPhysicalFunction.cpp) add_plugin(TemporalAtStBox PhysicalFunction nes-physical-operators TemporalAtStBoxPhysicalFunction.cpp) +endif() diff --git a/nes-plugins/CMakeLists.txt b/nes-plugins/CMakeLists.txt index e666dd616e..3d33385853 100644 --- a/nes-plugins/CMakeLists.txt +++ b/nes-plugins/CMakeLists.txt @@ -20,33 +20,36 @@ activate_optional_plugin("Sources/TCPSource" ON) # Enable the Generator source plugin; required by systests and repl tests activate_optional_plugin("Sources/GeneratorSource" ON) activate_optional_plugin("Sinks/VoidSink" ON) -activate_optional_plugin("Sources/MQTTSource" ON) -activate_optional_plugin("Sinks/MQTTSink" ON) - -# MEOS is a dependency -activate_optional_plugin("MEOS" ON) -message(STATUS "Enable MEOS Plugin") - -# Detect the platform -if (APPLE) - message(STATUS "Building on macOS") - # Set the include and library directories for Homebrew (macOS) - set(MEOS_INCLUDE_DIR "/opt/homebrew/include" CACHE PATH "Path to MEOS include directory") - set(MEOS_PLUGIN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE PATH "Path to MEOS plugin include directory") - include_directories(SYSTEM ${MEOS_INCLUDE_DIR} ${MEOS_PLUGIN_INCLUDE_DIR}) - include_directories(SYSTEM ${MEOS_INCLUDE_DIR} ${MEOS_PLUGIN_INCLUDE_DIR}) - link_directories(${MEOS_LIBRARY_DIR} ) - -else() - message(STATUS "Building on Linux") - - # Default behavior for Linux - find_package(meos REQUIRED) - if(meos_FOUND) - message(STATUS "MEOS found: include=${meos_INCLUDE_DIR}, library=${meos}") - include_directories(SYSTEM ${meos_INCLUDE_DIR}) +option(NES_ENABLE_MQTT "Enable MQTT source and sink plugins (requires PahoMqttCpp)" ON) +activate_optional_plugin("Sources/MQTTSource" ${NES_ENABLE_MQTT}) +activate_optional_plugin("Sinks/MQTTSink" ${NES_ENABLE_MQTT}) + +option(NES_ENABLE_MEOS "Enable MEOS plugin (requires libmeos installed on the system)" ON) +activate_optional_plugin("MEOS" ${NES_ENABLE_MEOS}) +if (NES_ENABLE_MEOS) + message(STATUS "Enable MEOS Plugin") + + # Detect the platform + if (APPLE) + message(STATUS "Building on macOS") + # Set the include and library directories for Homebrew (macOS) + set(MEOS_INCLUDE_DIR "/opt/homebrew/include" CACHE PATH "Path to MEOS include directory") + set(MEOS_PLUGIN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE PATH "Path to MEOS plugin include directory") + include_directories(SYSTEM ${MEOS_INCLUDE_DIR} ${MEOS_PLUGIN_INCLUDE_DIR}) + include_directories(SYSTEM ${MEOS_INCLUDE_DIR} ${MEOS_PLUGIN_INCLUDE_DIR}) + link_directories(${MEOS_LIBRARY_DIR} ) + else() - message(FATAL_ERROR "MEOS library not found") + message(STATUS "Building on Linux") + + # Default behavior for Linux + find_package(meos REQUIRED) + if(meos_FOUND) + message(STATUS "MEOS found: include=${meos_INCLUDE_DIR}, library=${meos}") + include_directories(SYSTEM ${meos_INCLUDE_DIR}) + else() + message(FATAL_ERROR "MEOS library not found") + endif() endif() endif() diff --git a/nes-plugins/Sinks/MQTTSink/CMakeLists.txt b/nes-plugins/Sinks/MQTTSink/CMakeLists.txt index 4bf42deeab..80b3122e89 100644 --- a/nes-plugins/Sinks/MQTTSink/CMakeLists.txt +++ b/nes-plugins/Sinks/MQTTSink/CMakeLists.txt @@ -23,5 +23,10 @@ target_include_directories(mqtt_sink_validation_plugin_library ) find_package(PahoMqttCpp CONFIG REQUIRED) -target_link_libraries(mqtt_sink_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) -target_link_libraries(mqtt_sink_validation_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) +if(TARGET PahoMqttCpp::paho-mqttpp3-static) + target_link_libraries(mqtt_sink_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) + target_link_libraries(mqtt_sink_validation_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) +else() + target_link_libraries(mqtt_sink_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3) + target_link_libraries(mqtt_sink_validation_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3) +endif() diff --git a/nes-plugins/Sources/MQTTSource/CMakeLists.txt b/nes-plugins/Sources/MQTTSource/CMakeLists.txt index 9f9ed0dd17..27db6702a0 100644 --- a/nes-plugins/Sources/MQTTSource/CMakeLists.txt +++ b/nes-plugins/Sources/MQTTSource/CMakeLists.txt @@ -23,5 +23,10 @@ target_include_directories(mqtt_source_validation_plugin_library ) find_package(PahoMqttCpp CONFIG REQUIRED) -target_link_libraries(mqtt_source_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) -target_link_libraries(mqtt_source_validation_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) +if(TARGET PahoMqttCpp::paho-mqttpp3-static) + target_link_libraries(mqtt_source_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) + target_link_libraries(mqtt_source_validation_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3-static) +else() + target_link_libraries(mqtt_source_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3) + target_link_libraries(mqtt_source_validation_plugin_library PRIVATE PahoMqttCpp::paho-mqttpp3) +endif() diff --git a/nes-query-optimizer/src/RewriteRules/LowerToPhysical/LowerToPhysicalWindowedAggregation.cpp b/nes-query-optimizer/src/RewriteRules/LowerToPhysical/LowerToPhysicalWindowedAggregation.cpp index c994b91a9d..eb667c31ed 100644 --- a/nes-query-optimizer/src/RewriteRules/LowerToPhysical/LowerToPhysicalWindowedAggregation.cpp +++ b/nes-query-optimizer/src/RewriteRules/LowerToPhysical/LowerToPhysicalWindowedAggregation.cpp @@ -54,8 +54,10 @@ #include #include // Special-case lowering for TEMPORAL_SEQUENCE (multi-input) aggregation +#ifdef NES_ENABLE_MEOS #include #include +#endif namespace NES { @@ -128,6 +130,7 @@ getAggregationPhysicalFunctions(const WindowedAggregationLogicalOperator& logica const auto name = descriptor->getName(); // Custom lowering path for TEMPORAL_SEQUENCE: needs three field functions (lon, lat, ts) +#ifdef NES_ENABLE_MEOS if (name == std::string_view("TemporalSequence")) { auto tsDescriptor = std::dynamic_pointer_cast(descriptor); @@ -159,6 +162,7 @@ getAggregationPhysicalFunctions(const WindowedAggregationLogicalOperator& logica aggregationPhysicalFunctions.push_back(std::move(phys)); continue; } +#endif // Default path: use registry for single-input aggregations auto aggregationInputFunction = QueryCompilation::FunctionProvider::lowerFunction(descriptor->onField); From a23e82941b27ec8f546f7ebe1e88feffd33927c0 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Thu, 11 Jun 2026 19:43:52 +0200 Subject: [PATCH 02/12] feat(nebula): wire per-event tfloat_sin/tfloat_cos/tfloat_tan (W44) Add TFLOAT_SIN, TFLOAT_COS, TFLOAT_TAN as per-event scalar operators following the extract-marshaler pattern from W25. Each takes (value:FLOAT64, ts:UINT64), constructs a MEOS single-instant temporal via tfloat_in, applies the trig C function, and extracts the FLOAT64 result via tfloat_start_value. Logical and physical function pairs registered as NES plugins; SQL parser extended with TFLOAT_SIN/COS/TAN tokens in the functionName rule and 2-arg case blocks. --- .../Meos/TfloatCosLogicalFunction.hpp | 53 +++++++++ .../Meos/TfloatSinLogicalFunction.hpp | 53 +++++++++ .../Meos/TfloatTanLogicalFunction.hpp | 53 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../Meos/TfloatCosLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatSinLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatTanLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatCosPhysicalFunction.hpp | 42 ++++++++ .../Meos/TfloatSinPhysicalFunction.hpp | 42 ++++++++ .../Meos/TfloatTanPhysicalFunction.hpp | 42 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../Meos/TfloatCosPhysicalFunction.cpp | 87 +++++++++++++++ .../Meos/TfloatSinPhysicalFunction.cpp | 87 +++++++++++++++ .../Meos/TfloatTanPhysicalFunction.cpp | 87 +++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 5 +- .../src/AntlrSQLQueryPlanCreator.cpp | 87 +++++++++++++++ 16 files changed, 949 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatCosLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatSinLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatTanLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatCosLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatSinLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatTanLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatCosPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatSinPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatTanPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatCosPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatSinPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatTanPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TfloatCosLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatCosLogicalFunction.hpp new file mode 100644 index 0000000000..24b170ae4a --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatCosLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_cos: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_cos`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatCosLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatCos"; + + TfloatCosLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatSinLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatSinLogicalFunction.hpp new file mode 100644 index 0000000000..310cc68ce4 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatSinLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_sin: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_sin`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatSinLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatSin"; + + TfloatSinLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatTanLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatTanLogicalFunction.hpp new file mode 100644 index 0000000000..e5a4fe48a1 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatTanLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_tan: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_tan`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatTanLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatTan"; + + TfloatTanLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 474ba11608..afc5785b55 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -18,3 +18,6 @@ add_plugin(TemporalAIntersectsGeometry LogicalFunction nes-logical-operators Tem add_plugin(TemporalEContainsGeometry LogicalFunction nes-logical-operators TemporalEContainsGeometryLogicalFunction.cpp) add_plugin(TemporalEDWithinGeometry LogicalFunction nes-logical-operators TemporalEDWithinGeometryLogicalFunction.cpp) add_plugin(TemporalAtStBox LogicalFunction nes-logical-operators TemporalAtStBoxLogicalFunction.cpp) +add_plugin(TfloatCos LogicalFunction nes-logical-operators TfloatCosLogicalFunction.cpp) +add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) +add_plugin(TfloatTan LogicalFunction nes-logical-operators TfloatTanLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TfloatCosLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatCosLogicalFunction.cpp new file mode 100644 index 0000000000..eb907da9d1 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatCosLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatCosLogicalFunction::TfloatCosLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatCosLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatCosLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatCosLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatCosLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatCosLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatCosLogicalFunction::getType() const { return NAME; } + +bool TfloatCosLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatCosLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatCosLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatCosLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatCosLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatCosLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatCosLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatSinLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatSinLogicalFunction.cpp new file mode 100644 index 0000000000..5c47c9dfb1 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatSinLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatSinLogicalFunction::TfloatSinLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatSinLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatSinLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatSinLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatSinLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatSinLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatSinLogicalFunction::getType() const { return NAME; } + +bool TfloatSinLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatSinLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatSinLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatSinLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatSinLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatSinLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatSinLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatTanLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatTanLogicalFunction.cpp new file mode 100644 index 0000000000..6ba0768d9f --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatTanLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatTanLogicalFunction::TfloatTanLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatTanLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatTanLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatTanLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatTanLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatTanLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatTanLogicalFunction::getType() const { return NAME; } + +bool TfloatTanLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatTanLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatTanLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatTanLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatTanLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatTanLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatTanLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatCosPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatCosPhysicalFunction.hpp new file mode 100644 index 0000000000..34d43117b7 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatCosPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_cos`. + * + * Per-event tfloat_cos: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatCosPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatCosPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatSinPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatSinPhysicalFunction.hpp new file mode 100644 index 0000000000..5e682a44fc --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatSinPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_sin`. + * + * Per-event tfloat_sin: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatSinPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatSinPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatTanPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatTanPhysicalFunction.hpp new file mode 100644 index 0000000000..0af2a0d03c --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatTanPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_tan`. + * + * Per-event tfloat_tan: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatTanPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatTanPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index cf83ac5aad..b6c45ca0c6 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -17,4 +17,7 @@ add_plugin(TemporalAIntersectsGeometry PhysicalFunction nes-physical-operators T add_plugin(TemporalEContainsGeometry PhysicalFunction nes-physical-operators TemporalEContainsGeometryPhysicalFunction.cpp) add_plugin(TemporalEDWithinGeometry PhysicalFunction nes-physical-operators TemporalEDWithinGeometryPhysicalFunction.cpp) add_plugin(TemporalAtStBox PhysicalFunction nes-physical-operators TemporalAtStBoxPhysicalFunction.cpp) +add_plugin(TfloatCos PhysicalFunction nes-physical-operators TfloatCosPhysicalFunction.cpp) +add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) +add_plugin(TfloatTan PhysicalFunction nes-physical-operators TfloatTanPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/TfloatCosPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatCosPhysicalFunction.cpp new file mode 100644 index 0000000000..0094b419db --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatCosPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatCosPhysicalFunction::TfloatCosPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatCosPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_cos(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatCosPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatCosPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatCosPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatSinPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatSinPhysicalFunction.cpp new file mode 100644 index 0000000000..de62924a86 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatSinPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatSinPhysicalFunction::TfloatSinPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatSinPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_sin(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatSinPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatSinPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatSinPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatTanPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatTanPhysicalFunction.cpp new file mode 100644 index 0000000000..0111ebc7ce --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatTanPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatTanPhysicalFunction::TfloatTanPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatTanPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_tan(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatTanPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatTanPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatTanPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 256726e087..9e6c7cdb13 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_COS | TFLOAT_SIN | TFLOAT_TAN; sinkClause: INTO sink (',' sink)*; @@ -488,6 +488,9 @@ TEMPORAL_AINTERSECTS_GEOMETRY: 'TEMPORAL_AINTERSECTS_GEOMETRY' | 'temporal_ainte TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains_geometry'; EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; +TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; +TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; +TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; WATERMARK: 'WATERMARK' | 'watermark'; OFFSET: 'OFFSET' | 'offset'; LOCALHOST: 'LOCALHOST' | 'localhost'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 4e9f1d7642..e3a39cb9ba 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -69,6 +69,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1187,6 +1190,90 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont TemporalAtStBoxLogicalFunction(lonFunction, latFunction, timestampFunction, stboxFunction, borderFlag)); } break; + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_COS */ + case AntlrSQLLexer::TFLOAT_COS: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_COS requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatCosLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_COS */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_SIN */ + case AntlrSQLLexer::TFLOAT_SIN: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_SIN requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatSinLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_SIN */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_TAN */ + case AntlrSQLLexer::TFLOAT_TAN: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_TAN requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatTanLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_TAN */ default: /// Check if the function is a constructor for a datatype From be23758e7d19e850366a54086bc5f09f39aee48d Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 00:24:55 +0200 Subject: [PATCH 03/12] feat(nebula): wire per-event tfloat_ceil/floor/radians/degrees (W45) Add TFLOAT_CEIL, TFLOAT_FLOOR, TFLOAT_RADIANS, TFLOAT_DEGREES as per-event scalar operators following the extract-marshaler pattern from W44. Each takes (value:FLOAT64, ts:UINT64), constructs a MEOS single-instant temporal via tfloat_in, applies the scalar C function, and extracts the FLOAT64 result via tfloat_start_value. TFLOAT_DEGREES hardcodes normalize=false. Logical and physical function pairs registered as NES plugins; SQL parser extended with TFLOAT_CEIL/FLOOR/RADIANS/DEGREES tokens in the functionName rule and 2-arg case blocks. --- .../Meos/TfloatCeilLogicalFunction.hpp | 53 ++++++++ .../Meos/TfloatDegreesLogicalFunction.hpp | 53 ++++++++ .../Meos/TfloatFloorLogicalFunction.hpp | 53 ++++++++ .../Meos/TfloatRadiansLogicalFunction.hpp | 53 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/TfloatCeilLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TfloatDegreesLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TfloatFloorLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TfloatRadiansLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TfloatCeilPhysicalFunction.hpp | 42 +++++++ .../Meos/TfloatDegreesPhysicalFunction.hpp | 42 +++++++ .../Meos/TfloatFloorPhysicalFunction.hpp | 42 +++++++ .../Meos/TfloatRadiansPhysicalFunction.hpp | 42 +++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/TfloatCeilPhysicalFunction.cpp | 87 +++++++++++++ .../Meos/TfloatDegreesPhysicalFunction.cpp | 87 +++++++++++++ .../Meos/TfloatFloorPhysicalFunction.cpp | 87 +++++++++++++ .../Meos/TfloatRadiansPhysicalFunction.cpp | 87 +++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 116 ++++++++++++++++++ 20 files changed, 1265 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatCeilLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatDegreesLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatFloorLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatRadiansLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatCeilLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatDegreesLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatFloorLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatRadiansLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatCeilPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatDegreesPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatFloorPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatRadiansPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatCeilPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatDegreesPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatFloorPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatRadiansPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TfloatCeilLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatCeilLogicalFunction.hpp new file mode 100644 index 0000000000..e731cb516a --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatCeilLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_ceil: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_ceil`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatCeilLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatCeil"; + + TfloatCeilLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatDegreesLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatDegreesLogicalFunction.hpp new file mode 100644 index 0000000000..80b70008c3 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatDegreesLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_degrees: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_degrees` (normalize=false). Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatDegreesLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatDegrees"; + + TfloatDegreesLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatFloorLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatFloorLogicalFunction.hpp new file mode 100644 index 0000000000..8734d8a205 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatFloorLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_floor: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_floor`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatFloorLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatFloor"; + + TfloatFloorLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatRadiansLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatRadiansLogicalFunction.hpp new file mode 100644 index 0000000000..cc5271f409 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatRadiansLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_radians: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_radians`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatRadiansLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatRadians"; + + TfloatRadiansLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index afc5785b55..42cd5a93f8 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -18,6 +18,10 @@ add_plugin(TemporalAIntersectsGeometry LogicalFunction nes-logical-operators Tem add_plugin(TemporalEContainsGeometry LogicalFunction nes-logical-operators TemporalEContainsGeometryLogicalFunction.cpp) add_plugin(TemporalEDWithinGeometry LogicalFunction nes-logical-operators TemporalEDWithinGeometryLogicalFunction.cpp) add_plugin(TemporalAtStBox LogicalFunction nes-logical-operators TemporalAtStBoxLogicalFunction.cpp) +add_plugin(TfloatCeil LogicalFunction nes-logical-operators TfloatCeilLogicalFunction.cpp) add_plugin(TfloatCos LogicalFunction nes-logical-operators TfloatCosLogicalFunction.cpp) +add_plugin(TfloatDegrees LogicalFunction nes-logical-operators TfloatDegreesLogicalFunction.cpp) +add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalFunction.cpp) +add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) add_plugin(TfloatTan LogicalFunction nes-logical-operators TfloatTanLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TfloatCeilLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatCeilLogicalFunction.cpp new file mode 100644 index 0000000000..79c19c517a --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatCeilLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatCeilLogicalFunction::TfloatCeilLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatCeilLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatCeilLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatCeilLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatCeilLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatCeilLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatCeilLogicalFunction::getType() const { return NAME; } + +bool TfloatCeilLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatCeilLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatCeilLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatCeilLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatCeilLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatCeilLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatCeilLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatDegreesLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatDegreesLogicalFunction.cpp new file mode 100644 index 0000000000..d7ecfd0f63 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatDegreesLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatDegreesLogicalFunction::TfloatDegreesLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatDegreesLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatDegreesLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatDegreesLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatDegreesLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatDegreesLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatDegreesLogicalFunction::getType() const { return NAME; } + +bool TfloatDegreesLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatDegreesLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatDegreesLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatDegreesLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatDegreesLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatDegreesLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatDegreesLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatFloorLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatFloorLogicalFunction.cpp new file mode 100644 index 0000000000..3c9196c92e --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatFloorLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatFloorLogicalFunction::TfloatFloorLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatFloorLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatFloorLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatFloorLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatFloorLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatFloorLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatFloorLogicalFunction::getType() const { return NAME; } + +bool TfloatFloorLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatFloorLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatFloorLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatFloorLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatFloorLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatFloorLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatFloorLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatRadiansLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatRadiansLogicalFunction.cpp new file mode 100644 index 0000000000..fff28b7bca --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatRadiansLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatRadiansLogicalFunction::TfloatRadiansLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatRadiansLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatRadiansLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatRadiansLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatRadiansLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatRadiansLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatRadiansLogicalFunction::getType() const { return NAME; } + +bool TfloatRadiansLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatRadiansLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatRadiansLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatRadiansLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatRadiansLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatRadiansLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatRadiansLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatCeilPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatCeilPhysicalFunction.hpp new file mode 100644 index 0000000000..984628086f --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatCeilPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_ceil`. + * + * Per-event tfloat_ceil: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatCeilPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatCeilPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatDegreesPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatDegreesPhysicalFunction.hpp new file mode 100644 index 0000000000..261eb72f71 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatDegreesPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_degrees`. + * + * Per-event tfloat_degrees (normalize=false): single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatDegreesPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatDegreesPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatFloorPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatFloorPhysicalFunction.hpp new file mode 100644 index 0000000000..0e557615a4 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatFloorPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_floor`. + * + * Per-event tfloat_floor: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatFloorPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatFloorPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatRadiansPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatRadiansPhysicalFunction.hpp new file mode 100644 index 0000000000..35d25c6f0b --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatRadiansPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_radians`. + * + * Per-event tfloat_radians: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatRadiansPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatRadiansPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index b6c45ca0c6..01078c3d7e 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -17,7 +17,11 @@ add_plugin(TemporalAIntersectsGeometry PhysicalFunction nes-physical-operators T add_plugin(TemporalEContainsGeometry PhysicalFunction nes-physical-operators TemporalEContainsGeometryPhysicalFunction.cpp) add_plugin(TemporalEDWithinGeometry PhysicalFunction nes-physical-operators TemporalEDWithinGeometryPhysicalFunction.cpp) add_plugin(TemporalAtStBox PhysicalFunction nes-physical-operators TemporalAtStBoxPhysicalFunction.cpp) +add_plugin(TfloatCeil PhysicalFunction nes-physical-operators TfloatCeilPhysicalFunction.cpp) add_plugin(TfloatCos PhysicalFunction nes-physical-operators TfloatCosPhysicalFunction.cpp) +add_plugin(TfloatDegrees PhysicalFunction nes-physical-operators TfloatDegreesPhysicalFunction.cpp) +add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysicalFunction.cpp) +add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) add_plugin(TfloatTan PhysicalFunction nes-physical-operators TfloatTanPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/TfloatCeilPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatCeilPhysicalFunction.cpp new file mode 100644 index 0000000000..bb3c5d6d7b --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatCeilPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatCeilPhysicalFunction::TfloatCeilPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatCeilPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_ceil(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatCeilPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatCeilPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatCeilPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatDegreesPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatDegreesPhysicalFunction.cpp new file mode 100644 index 0000000000..30871136e7 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatDegreesPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatDegreesPhysicalFunction::TfloatDegreesPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatDegreesPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_degrees(temp, false); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatDegreesPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatDegreesPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatDegreesPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatFloorPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatFloorPhysicalFunction.cpp new file mode 100644 index 0000000000..3a3ba34521 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatFloorPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatFloorPhysicalFunction::TfloatFloorPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatFloorPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_floor(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatFloorPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatFloorPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatFloorPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatRadiansPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatRadiansPhysicalFunction.cpp new file mode 100644 index 0000000000..7988802ffb --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatRadiansPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatRadiansPhysicalFunction::TfloatRadiansPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatRadiansPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_radians(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatRadiansPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatRadiansPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatRadiansPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 9e6c7cdb13..27c7a40be8 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_COS | TFLOAT_SIN | TFLOAT_TAN; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SIN | TFLOAT_TAN; sinkClause: INTO sink (',' sink)*; @@ -488,7 +488,11 @@ TEMPORAL_AINTERSECTS_GEOMETRY: 'TEMPORAL_AINTERSECTS_GEOMETRY' | 'temporal_ainte TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains_geometry'; EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; +TFLOAT_CEIL: 'TFLOAT_CEIL' | 'tfloat_ceil'; TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; +TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; +TFLOAT_FLOOR: 'TFLOAT_FLOOR' | 'tfloat_floor'; +TFLOAT_RADIANS: 'TFLOAT_RADIANS' | 'tfloat_radians'; TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; WATERMARK: 'WATERMARK' | 'watermark'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index e3a39cb9ba..48405d5879 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -69,7 +69,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include #include @@ -1274,6 +1278,118 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_TAN */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_CEIL */ + case AntlrSQLLexer::TFLOAT_CEIL: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_CEIL requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatCeilLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_CEIL */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_DEGREES */ + case AntlrSQLLexer::TFLOAT_DEGREES: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_DEGREES requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatDegreesLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_DEGREES */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_FLOOR */ + case AntlrSQLLexer::TFLOAT_FLOOR: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_FLOOR requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatFloorLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_FLOOR */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_RADIANS */ + case AntlrSQLLexer::TFLOAT_RADIANS: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_RADIANS requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatRadiansLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_RADIANS */ default: /// Check if the function is a constructor for a datatype From 384c4c3d8c79e3c6853237cd61b1dec3f00b16c3 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 05:22:56 +0200 Subject: [PATCH 04/12] feat(nebula): wire per-event tfloat_shift_value/scale_value (W46) Add TFLOAT_SHIFT_VALUE and TFLOAT_SCALE_VALUE as per-event scalar operators following the extract-marshaler pattern. Each takes (value:FLOAT64, ts:UINT64, param:FLOAT64), constructs a MEOS single-instant temporal via tfloat_in, applies the shift or scale, and extracts the FLOAT64 result via tfloat_start_value. Logical and physical function pairs registered as NES plugins; SQL parser extended with TFLOAT_SHIFT_VALUE/SCALE_VALUE tokens in the functionName rule and 3-arg case blocks. --- .../Meos/TfloatScaleValueLogicalFunction.hpp | 54 +++++++++ .../Meos/TfloatShiftValueLogicalFunction.hpp | 54 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 2 + .../Meos/TfloatScaleValueLogicalFunction.cpp | 105 ++++++++++++++++++ .../Meos/TfloatShiftValueLogicalFunction.cpp | 105 ++++++++++++++++++ .../Meos/TfloatScaleValuePhysicalFunction.hpp | 44 ++++++++ .../Meos/TfloatShiftValuePhysicalFunction.hpp | 44 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 2 + .../Meos/TfloatScaleValuePhysicalFunction.cpp | 91 +++++++++++++++ .../Meos/TfloatShiftValuePhysicalFunction.cpp | 91 +++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 4 +- .../src/AntlrSQLQueryPlanCreator.cpp | 60 ++++++++++ 12 files changed, 655 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatScaleValueLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatShiftValueLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatScaleValueLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatShiftValueLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatScaleValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatShiftValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatScaleValuePhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatShiftValuePhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TfloatScaleValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatScaleValueLogicalFunction.hpp new file mode 100644 index 0000000000..ad47c78148 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatScaleValueLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_scale_value: scales the value of a single-instant tfloat by a width. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_scale_value`. Takes (value:FLOAT64, ts:UINT64, width:FLOAT64), + * constructs a single-instant temporal, applies the scale, and returns FLOAT64. + */ +class TfloatScaleValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatScaleValue"; + + TfloatScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction width); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatShiftValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatShiftValueLogicalFunction.hpp new file mode 100644 index 0000000000..7d721d6c1b --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatShiftValueLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_shift_value: shifts the value of a single-instant tfloat by a scalar. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_shift_value`. Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64), + * constructs a single-instant temporal, applies the shift, and returns FLOAT64. + */ +class TfloatShiftValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatShiftValue"; + + TfloatShiftValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 42cd5a93f8..6b1d4b92fa 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -23,5 +23,7 @@ add_plugin(TfloatCos LogicalFunction nes-logical-operators TfloatCosLogicalFunct add_plugin(TfloatDegrees LogicalFunction nes-logical-operators TfloatDegreesLogicalFunction.cpp) add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalFunction.cpp) add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) +add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) +add_plugin(TfloatShiftValue LogicalFunction nes-logical-operators TfloatShiftValueLogicalFunction.cpp) add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) add_plugin(TfloatTan LogicalFunction nes-logical-operators TfloatTanLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TfloatScaleValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatScaleValueLogicalFunction.cpp new file mode 100644 index 0000000000..7631f17ea6 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatScaleValueLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatScaleValueLogicalFunction::TfloatScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction width) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(width)); +} + +DataType TfloatScaleValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatScaleValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatScaleValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatScaleValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TfloatScaleValueLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatScaleValueLogicalFunction::getType() const { return NAME; } + +bool TfloatScaleValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatScaleValueLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatScaleValueLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatScaleValueLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatScaleValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TfloatScaleValueLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TfloatScaleValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatShiftValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatShiftValueLogicalFunction.cpp new file mode 100644 index 0000000000..d4c4cea5de --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatShiftValueLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatShiftValueLogicalFunction::TfloatShiftValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(shift)); +} + +DataType TfloatShiftValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatShiftValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatShiftValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatShiftValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TfloatShiftValueLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatShiftValueLogicalFunction::getType() const { return NAME; } + +bool TfloatShiftValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatShiftValueLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatShiftValueLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatShiftValueLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatShiftValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TfloatShiftValueLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TfloatShiftValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatScaleValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatScaleValuePhysicalFunction.hpp new file mode 100644 index 0000000000..776ae3e08b --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatScaleValuePhysicalFunction.hpp @@ -0,0 +1,44 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_scale_value`. + * + * Per-event tfloat_scale_value: scales a single-instant tfloat by a width, value extracted -> double. + * Takes (value:FLOAT64, ts:UINT64, width:FLOAT64). + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatScaleValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction widthFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatShiftValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatShiftValuePhysicalFunction.hpp new file mode 100644 index 0000000000..f8cc2632b2 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatShiftValuePhysicalFunction.hpp @@ -0,0 +1,44 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_shift_value`. + * + * Per-event tfloat_shift_value: shifts a single-instant tfloat by a scalar, value extracted -> double. + * Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64). + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatShiftValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatShiftValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index 01078c3d7e..d62de9237e 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -22,6 +22,8 @@ add_plugin(TfloatCos PhysicalFunction nes-physical-operators TfloatCosPhysicalFu add_plugin(TfloatDegrees PhysicalFunction nes-physical-operators TfloatDegreesPhysicalFunction.cpp) add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysicalFunction.cpp) add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) +add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) +add_plugin(TfloatShiftValue PhysicalFunction nes-physical-operators TfloatShiftValuePhysicalFunction.cpp) add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) add_plugin(TfloatTan PhysicalFunction nes-physical-operators TfloatTanPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/TfloatScaleValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatScaleValuePhysicalFunction.cpp new file mode 100644 index 0000000000..ddf3cb4de1 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatScaleValuePhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatScaleValuePhysicalFunction::TfloatScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction widthFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(widthFunction)); +} + +VarVal TfloatScaleValuePhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto width = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double width) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_scale_value(temp, width); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, width); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatScaleValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TfloatScaleValuePhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TfloatScaleValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatShiftValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatShiftValuePhysicalFunction.cpp new file mode 100644 index 0000000000..3f5de19d9f --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatShiftValuePhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatShiftValuePhysicalFunction::TfloatShiftValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(shiftFunction)); +} + +VarVal TfloatShiftValuePhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto shift = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double shift) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_shift_value(temp, shift); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, shift); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatShiftValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TfloatShiftValuePhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TfloatShiftValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 27c7a40be8..8f7b599c8e 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SIN | TFLOAT_TAN; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN; sinkClause: INTO sink (',' sink)*; @@ -493,6 +493,8 @@ TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; TFLOAT_FLOOR: 'TFLOAT_FLOOR' | 'tfloat_floor'; TFLOAT_RADIANS: 'TFLOAT_RADIANS' | 'tfloat_radians'; +TFLOAT_SCALE_VALUE: 'TFLOAT_SCALE_VALUE' | 'tfloat_scale_value'; +TFLOAT_SHIFT_VALUE: 'TFLOAT_SHIFT_VALUE' | 'tfloat_shift_value'; TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; WATERMARK: 'WATERMARK' | 'watermark'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 48405d5879..ef6e63e327 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -74,6 +74,8 @@ #include #include #include +#include +#include #include #include #include @@ -1390,6 +1392,64 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_RADIANS */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_SCALE_VALUE */ + case AntlrSQLLexer::TFLOAT_SCALE_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TFLOAT_SCALE_VALUE requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatScaleValueLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_SCALE_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_SHIFT_VALUE */ + case AntlrSQLLexer::TFLOAT_SHIFT_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TFLOAT_SHIFT_VALUE requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatShiftValueLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_SHIFT_VALUE */ default: /// Check if the function is a constructor for a datatype From 02ee1160ca170b0736e98eed048d205bb8bd2762 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 05:29:41 +0200 Subject: [PATCH 05/12] feat(meos): add TNUMBER_ABS and TFLOAT_SHIFT_SCALE_VALUE NES operators (W47) Adds per-event NES operators backed by `tnumber_abs` (2-arg: value, ts) and `tfloat_shift_scale_value` (4-arg: value, ts, shift, width). Each operator constructs a single-instant tfloat, applies the MEOS function, and returns the resulting double. Logical/physical function pairs, plugin registrations, grammar tokens, and parser case blocks are included. --- .../TfloatShiftScaleValueLogicalFunction.hpp | 55 +++++++++ .../Meos/TnumberAbsLogicalFunction.hpp | 53 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 2 + .../TfloatShiftScaleValueLogicalFunction.cpp | 108 ++++++++++++++++++ .../Meos/TnumberAbsLogicalFunction.cpp | 102 +++++++++++++++++ .../TfloatShiftScaleValuePhysicalFunction.hpp | 44 +++++++ .../Meos/TnumberAbsPhysicalFunction.hpp | 42 +++++++ .../src/Functions/Meos/CMakeLists.txt | 2 + .../TfloatShiftScaleValuePhysicalFunction.cpp | 95 +++++++++++++++ .../Meos/TnumberAbsPhysicalFunction.cpp | 87 ++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 4 +- .../src/AntlrSQLQueryPlanCreator.cpp | 60 ++++++++++ 12 files changed, 653 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatShiftScaleValueLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TnumberAbsLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatShiftScaleValueLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TnumberAbsLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TnumberAbsPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TnumberAbsPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TfloatShiftScaleValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatShiftScaleValueLogicalFunction.hpp new file mode 100644 index 0000000000..b4c2b90990 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatShiftScaleValueLogicalFunction.hpp @@ -0,0 +1,55 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_shift_scale_value: shifts and scales a single-instant tfloat by shift and width. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_shift_scale_value`. Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64, width:FLOAT64), + * constructs a single-instant temporal, applies shift+scale, and returns FLOAT64. + */ +class TfloatShiftScaleValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatShiftScaleValue"; + + TfloatShiftScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift, + LogicalFunction width); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TnumberAbsLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TnumberAbsLogicalFunction.hpp new file mode 100644 index 0000000000..6fe10d29d1 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TnumberAbsLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tnumber_abs: single-instant tnumber transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tnumber_abs`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TnumberAbsLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TnumberAbs"; + + TnumberAbsLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 6b1d4b92fa..01154d9eee 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -24,6 +24,8 @@ add_plugin(TfloatDegrees LogicalFunction nes-logical-operators TfloatDegreesLogi add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalFunction.cpp) add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) +add_plugin(TfloatShiftScaleValue LogicalFunction nes-logical-operators TfloatShiftScaleValueLogicalFunction.cpp) add_plugin(TfloatShiftValue LogicalFunction nes-logical-operators TfloatShiftValueLogicalFunction.cpp) add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) add_plugin(TfloatTan LogicalFunction nes-logical-operators TfloatTanLogicalFunction.cpp) +add_plugin(TnumberAbs LogicalFunction nes-logical-operators TnumberAbsLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TfloatShiftScaleValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatShiftScaleValueLogicalFunction.cpp new file mode 100644 index 0000000000..ef6f4c2a71 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatShiftScaleValueLogicalFunction.cpp @@ -0,0 +1,108 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatShiftScaleValueLogicalFunction::TfloatShiftScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift, + LogicalFunction width) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(4); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(shift)); + parameters.push_back(std::move(width)); +} + +DataType TfloatShiftScaleValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatShiftScaleValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatShiftScaleValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatShiftScaleValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 4, "TfloatShiftScaleValueLogicalFunction requires 4 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatShiftScaleValueLogicalFunction::getType() const { return NAME; } + +bool TfloatShiftScaleValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatShiftScaleValueLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatShiftScaleValueLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatShiftScaleValueLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatShiftScaleValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 4, + "TfloatShiftScaleValueLogicalFunction requires 4 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + auto arg3 = std::move(arguments.children[3]); + return TfloatShiftScaleValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2), std::move(arg3)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TnumberAbsLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TnumberAbsLogicalFunction.cpp new file mode 100644 index 0000000000..5b67053833 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TnumberAbsLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TnumberAbsLogicalFunction::TnumberAbsLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TnumberAbsLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TnumberAbsLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TnumberAbsLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TnumberAbsLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TnumberAbsLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TnumberAbsLogicalFunction::getType() const { return NAME; } + +bool TnumberAbsLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TnumberAbsLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TnumberAbsLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TnumberAbsLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTnumberAbsLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TnumberAbsLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TnumberAbsLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.hpp new file mode 100644 index 0000000000..efdb1e1c98 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.hpp @@ -0,0 +1,44 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_shift_scale_value`. + * + * Per-event tfloat_shift_scale_value: shifts and scales a single-instant tfloat. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatShiftScaleValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatShiftScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction, + PhysicalFunction widthFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TnumberAbsPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TnumberAbsPhysicalFunction.hpp new file mode 100644 index 0000000000..9c1c46c10d --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TnumberAbsPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tnumber_abs`. + * + * Per-event tnumber_abs: single-instant tnumber transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TnumberAbsPhysicalFunction : public PhysicalFunctionConcept { +public: + TnumberAbsPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index d62de9237e..ad801dc314 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -23,7 +23,9 @@ add_plugin(TfloatDegrees PhysicalFunction nes-physical-operators TfloatDegreesPh add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysicalFunction.cpp) add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) +add_plugin(TfloatShiftScaleValue PhysicalFunction nes-physical-operators TfloatShiftScaleValuePhysicalFunction.cpp) add_plugin(TfloatShiftValue PhysicalFunction nes-physical-operators TfloatShiftValuePhysicalFunction.cpp) add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) add_plugin(TfloatTan PhysicalFunction nes-physical-operators TfloatTanPhysicalFunction.cpp) +add_plugin(TnumberAbs PhysicalFunction nes-physical-operators TnumberAbsPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.cpp new file mode 100644 index 0000000000..7095a9c943 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatShiftScaleValuePhysicalFunction.cpp @@ -0,0 +1,95 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatShiftScaleValuePhysicalFunction::TfloatShiftScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction, + PhysicalFunction widthFunction) +{ + parameterFunctions.reserve(4); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(shiftFunction)); + parameterFunctions.push_back(std::move(widthFunction)); +} + +VarVal TfloatShiftScaleValuePhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto shift = parameterValues[2].cast>(); + auto width = parameterValues[3].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double shift, double width) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_shift_scale_value(temp, shift, width); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, shift, width); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatShiftScaleValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 4, + "TfloatShiftScaleValuePhysicalFunction requires 4 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + auto arg3 = std::move(arguments.childFunctions[3]); + return TfloatShiftScaleValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2), std::move(arg3)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TnumberAbsPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TnumberAbsPhysicalFunction.cpp new file mode 100644 index 0000000000..d61f38178c --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TnumberAbsPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TnumberAbsPhysicalFunction::TnumberAbsPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TnumberAbsPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tnumber_abs(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTnumberAbsPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TnumberAbsPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TnumberAbsPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 8f7b599c8e..eaeea079a1 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -494,9 +494,11 @@ TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; TFLOAT_FLOOR: 'TFLOAT_FLOOR' | 'tfloat_floor'; TFLOAT_RADIANS: 'TFLOAT_RADIANS' | 'tfloat_radians'; TFLOAT_SCALE_VALUE: 'TFLOAT_SCALE_VALUE' | 'tfloat_scale_value'; +TFLOAT_SHIFT_SCALE_VALUE: 'TFLOAT_SHIFT_SCALE_VALUE' | 'tfloat_shift_scale_value'; TFLOAT_SHIFT_VALUE: 'TFLOAT_SHIFT_VALUE' | 'tfloat_shift_value'; TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; +TNUMBER_ABS: 'TNUMBER_ABS' | 'tnumber_abs'; WATERMARK: 'WATERMARK' | 'watermark'; OFFSET: 'OFFSET' | 'offset'; LOCALHOST: 'LOCALHOST' | 'localhost'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index ef6e63e327..1043181e7a 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -75,9 +75,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -1450,6 +1452,64 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_SHIFT_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_SHIFT_SCALE_VALUE */ + case AntlrSQLLexer::TFLOAT_SHIFT_SCALE_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 4) + throw InvalidQuerySyntax("TFLOAT_SHIFT_SCALE_VALUE requires exactly 4 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a3 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatShiftScaleValueLogicalFunction(a0, a1, a2, a3)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_SHIFT_SCALE_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TNUMBER_ABS */ + case AntlrSQLLexer::TNUMBER_ABS: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TNUMBER_ABS requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TnumberAbsLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TNUMBER_ABS */ default: /// Check if the function is a constructor for a datatype From 6ff9b082e5f0e25fcf9fe48a4d54adc3fe8ee247 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 05:35:38 +0200 Subject: [PATCH 06/12] feat(meos): add ADD/SUB/MUL/DIV_TFLOAT_FLOAT NES operators (W48) Adds per-event NES operators backed by `add_tfloat_float`, `sub_tfloat_float`, `mul_tfloat_float`, and `div_tfloat_float` (3-arg each: value, ts, scalar). Each operator constructs a single-instant tfloat, applies the MEOS arithmetic function against a constant scalar, and returns the resulting double. Logical/physical function pairs, plugin registrations, grammar tokens, and parser case blocks are included. --- .../Meos/AddTfloatFloatLogicalFunction.hpp | 54 ++++++++ .../Meos/DivTfloatFloatLogicalFunction.hpp | 54 ++++++++ .../Meos/MulTfloatFloatLogicalFunction.hpp | 54 ++++++++ .../Meos/SubTfloatFloatLogicalFunction.hpp | 54 ++++++++ .../Meos/AddTfloatFloatLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTfloatFloatLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulTfloatFloatLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubTfloatFloatLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/AddTfloatFloatPhysicalFunction.hpp | 43 +++++++ .../Meos/DivTfloatFloatPhysicalFunction.hpp | 43 +++++++ .../Meos/MulTfloatFloatPhysicalFunction.hpp | 43 +++++++ .../Meos/SubTfloatFloatPhysicalFunction.hpp | 43 +++++++ .../Meos/AddTfloatFloatPhysicalFunction.cpp | 91 +++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTfloatFloatPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/MulTfloatFloatPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/SubTfloatFloatPhysicalFunction.cpp | 91 +++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 120 ++++++++++++++++++ 20 files changed, 1305 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/AddTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubTfloatFloatLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubTfloatFloatPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..7fbbb663c8 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddTfloatFloatLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event add_tfloat_float: adds a constant to a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_tfloat_float`. Takes (value:FLOAT64, ts:UINT64, addend:FLOAT64), + * constructs a single-instant temporal, applies the addition, and returns FLOAT64. + */ +class AddTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddTfloatFloat"; + + AddTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction addend); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/DivTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..f028b28994 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivTfloatFloatLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event div_tfloat_float: divides a single-instant tfloat value by a constant. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_tfloat_float`. Takes (value:FLOAT64, ts:UINT64, divisor:FLOAT64), + * constructs a single-instant temporal, applies the division, and returns FLOAT64. + */ +class DivTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivTfloatFloat"; + + DivTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction divisor); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/MulTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..a2f3606cca --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulTfloatFloatLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event mul_tfloat_float: multiplies a single-instant tfloat value by a constant. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_tfloat_float`. Takes (value:FLOAT64, ts:UINT64, factor:FLOAT64), + * constructs a single-instant temporal, applies the multiplication, and returns FLOAT64. + */ +class MulTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulTfloatFloat"; + + MulTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction factor); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/SubTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..ea5a1a9d26 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubTfloatFloatLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event sub_tfloat_float: subtracts a constant from a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_tfloat_float`. Takes (value:FLOAT64, ts:UINT64, subtrahend:FLOAT64), + * constructs a single-instant temporal, applies the subtraction, and returns FLOAT64. + */ +class SubTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubTfloatFloat"; + + SubTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction subtrahend); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AddTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..6cc26a04a5 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddTfloatFloatLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +AddTfloatFloatLogicalFunction::AddTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction addend) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(addend)); +} + +DataType AddTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AddTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddTfloatFloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction AddTfloatFloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction AddTfloatFloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterAddTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddTfloatFloatLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return AddTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 01154d9eee..1f40833d3b 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -24,6 +24,10 @@ add_plugin(TfloatDegrees LogicalFunction nes-logical-operators TfloatDegreesLogi add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalFunction.cpp) add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) +add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) +add_plugin(DivTfloatFloat LogicalFunction nes-logical-operators DivTfloatFloatLogicalFunction.cpp) +add_plugin(MulTfloatFloat LogicalFunction nes-logical-operators MulTfloatFloatLogicalFunction.cpp) +add_plugin(SubTfloatFloat LogicalFunction nes-logical-operators SubTfloatFloatLogicalFunction.cpp) add_plugin(TfloatShiftScaleValue LogicalFunction nes-logical-operators TfloatShiftScaleValueLogicalFunction.cpp) add_plugin(TfloatShiftValue LogicalFunction nes-logical-operators TfloatShiftValueLogicalFunction.cpp) add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/DivTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..a9bb9268b7 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivTfloatFloatLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +DivTfloatFloatLogicalFunction::DivTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction divisor) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(divisor)); +} + +DataType DivTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool DivTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivTfloatFloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction DivTfloatFloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction DivTfloatFloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterDivTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivTfloatFloatLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return DivTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..c28dba03cf --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulTfloatFloatLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +MulTfloatFloatLogicalFunction::MulTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction factor) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(factor)); +} + +DataType MulTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool MulTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulTfloatFloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction MulTfloatFloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction MulTfloatFloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterMulTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulTfloatFloatLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return MulTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..d1eda09525 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubTfloatFloatLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +SubTfloatFloatLogicalFunction::SubTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction subtrahend) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(subtrahend)); +} + +DataType SubTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool SubTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubTfloatFloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction SubTfloatFloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction SubTfloatFloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterSubTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubTfloatFloatLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return SubTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..599af33b95 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddTfloatFloatPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `add_tfloat_float`. + * + * Per-event add_tfloat_float: adds a constant to a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AddTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction addendFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/DivTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..c221eba2e9 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivTfloatFloatPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `div_tfloat_float`. + * + * Per-event div_tfloat_float: divides a single-instant tfloat value by a constant. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + DivTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction divisorFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/MulTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..5014e03f50 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulTfloatFloatPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `mul_tfloat_float`. + * + * Per-event mul_tfloat_float: multiplies a single-instant tfloat value by a constant. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + MulTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction factorFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/SubTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..f1ed79336a --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubTfloatFloatPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `sub_tfloat_float`. + * + * Per-event sub_tfloat_float: subtracts a constant from a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + SubTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction subtrahendFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AddTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..75dc0a3994 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddTfloatFloatPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +AddTfloatFloatPhysicalFunction::AddTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction addendFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(addendFunction)); +} + +VarVal AddTfloatFloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto addend = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double addend) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = add_tfloat_float(temp, addend); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, addend); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddTfloatFloatPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return AddTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index ad801dc314..fcfbe5b9ba 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -23,6 +23,10 @@ add_plugin(TfloatDegrees PhysicalFunction nes-physical-operators TfloatDegreesPh add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysicalFunction.cpp) add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) +add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) +add_plugin(DivTfloatFloat PhysicalFunction nes-physical-operators DivTfloatFloatPhysicalFunction.cpp) +add_plugin(MulTfloatFloat PhysicalFunction nes-physical-operators MulTfloatFloatPhysicalFunction.cpp) +add_plugin(SubTfloatFloat PhysicalFunction nes-physical-operators SubTfloatFloatPhysicalFunction.cpp) add_plugin(TfloatShiftScaleValue PhysicalFunction nes-physical-operators TfloatShiftScaleValuePhysicalFunction.cpp) add_plugin(TfloatShiftValue PhysicalFunction nes-physical-operators TfloatShiftValuePhysicalFunction.cpp) add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/DivTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..c0f7e9da02 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivTfloatFloatPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +DivTfloatFloatPhysicalFunction::DivTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction divisorFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(divisorFunction)); +} + +VarVal DivTfloatFloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto divisor = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double divisor) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = div_tfloat_float(temp, divisor); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, divisor); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivTfloatFloatPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return DivTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..80205907b6 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulTfloatFloatPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +MulTfloatFloatPhysicalFunction::MulTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction factorFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(factorFunction)); +} + +VarVal MulTfloatFloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto factor = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double factor) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = mul_tfloat_float(temp, factor); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, factor); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulTfloatFloatPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return MulTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..75e6eb5c39 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubTfloatFloatPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +SubTfloatFloatPhysicalFunction::SubTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction subtrahendFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(subtrahendFunction)); +} + +VarVal SubTfloatFloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto subtrahend = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double subtrahend) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = sub_tfloat_float(temp, subtrahend); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, subtrahend); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubTfloatFloatPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return SubTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index eaeea079a1..893cd4b5d3 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | DIV_TFLOAT_FLOAT | MUL_TFLOAT_FLOAT | SUB_TFLOAT_FLOAT | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -488,6 +488,10 @@ TEMPORAL_AINTERSECTS_GEOMETRY: 'TEMPORAL_AINTERSECTS_GEOMETRY' | 'temporal_ainte TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains_geometry'; EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; +ADD_TFLOAT_FLOAT: 'ADD_TFLOAT_FLOAT' | 'add_tfloat_float'; +DIV_TFLOAT_FLOAT: 'DIV_TFLOAT_FLOAT' | 'div_tfloat_float'; +MUL_TFLOAT_FLOAT: 'MUL_TFLOAT_FLOAT' | 'mul_tfloat_float'; +SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; TFLOAT_CEIL: 'TFLOAT_CEIL' | 'tfloat_ceil'; TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 1043181e7a..6fc7f008dc 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -69,6 +69,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -1510,6 +1514,122 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TNUMBER_ABS */ + /* BEGIN CODEGEN PARSER GLUE: ADD_TFLOAT_FLOAT */ + case AntlrSQLLexer::ADD_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_TFLOAT_FLOAT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(AddTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: DIV_TFLOAT_FLOAT */ + case AntlrSQLLexer::DIV_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_TFLOAT_FLOAT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(DivTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: MUL_TFLOAT_FLOAT */ + case AntlrSQLLexer::MUL_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_TFLOAT_FLOAT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(MulTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ + case AntlrSQLLexer::SUB_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_TFLOAT_FLOAT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(SubTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ default: /// Check if the function is a constructor for a datatype From d376592e03840130b55e045d7733b36c5e15a53b Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 05:44:15 +0200 Subject: [PATCH 07/12] feat(meos): add ADD/SUB/MUL/DIV_TNUMBER_TNUMBER NES operators (W49) Adds per-event NES operators backed by `add_tnumber_tnumber`, `sub_tnumber_tnumber`, `mul_tnumber_tnumber`, and `div_tnumber_tnumber` (3-arg each: value1, value2, shared-ts). Each operator constructs two co-instant tfloats, applies the MEOS element-wise arithmetic function, and returns the resulting double. Logical/physical function pairs, plugin registrations, grammar tokens, and parser case blocks are included. --- .../Meos/AddTnumberTnumberLogicalFunction.hpp | 54 ++++++++ .../Meos/DivTnumberTnumberLogicalFunction.hpp | 54 ++++++++ .../Meos/MulTnumberTnumberLogicalFunction.hpp | 54 ++++++++ .../Meos/SubTnumberTnumberLogicalFunction.hpp | 54 ++++++++ .../Meos/AddTnumberTnumberLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTnumberTnumberLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulTnumberTnumberLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubTnumberTnumberLogicalFunction.cpp | 105 +++++++++++++++ .../AddTnumberTnumberPhysicalFunction.hpp | 43 +++++++ .../DivTnumberTnumberPhysicalFunction.hpp | 43 +++++++ .../MulTnumberTnumberPhysicalFunction.hpp | 43 +++++++ .../SubTnumberTnumberPhysicalFunction.hpp | 43 +++++++ .../AddTnumberTnumberPhysicalFunction.cpp | 94 ++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../DivTnumberTnumberPhysicalFunction.cpp | 94 ++++++++++++++ .../MulTnumberTnumberPhysicalFunction.cpp | 94 ++++++++++++++ .../SubTnumberTnumberPhysicalFunction.cpp | 94 ++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 120 ++++++++++++++++++ 20 files changed, 1317 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/AddTnumberTnumberLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivTnumberTnumberLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulTnumberTnumberLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubTnumberTnumberLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddTnumberTnumberLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivTnumberTnumberLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulTnumberTnumberLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubTnumberTnumberLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddTnumberTnumberPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivTnumberTnumberPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulTnumberTnumberPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubTnumberTnumberPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddTnumberTnumberPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivTnumberTnumberPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulTnumberTnumberPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubTnumberTnumberPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddTnumberTnumberLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddTnumberTnumberLogicalFunction.hpp new file mode 100644 index 0000000000..eb6bf59984 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddTnumberTnumberLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event add_tnumber_tnumber: element-wise addition of two single-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_tnumber_tnumber`. Takes (value1:FLOAT64, value2:FLOAT64, ts:UINT64), + * constructs two co-instant temporals, applies the addition, and returns FLOAT64. + */ +class AddTnumberTnumberLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddTnumberTnumber"; + + AddTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/DivTnumberTnumberLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivTnumberTnumberLogicalFunction.hpp new file mode 100644 index 0000000000..e85de51c18 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivTnumberTnumberLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event div_tnumber_tnumber: element-wise division of two single-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_tnumber_tnumber`. Takes (value1:FLOAT64, value2:FLOAT64, ts:UINT64), + * constructs two co-instant temporals, applies the division, and returns FLOAT64. + */ +class DivTnumberTnumberLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivTnumberTnumber"; + + DivTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/MulTnumberTnumberLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulTnumberTnumberLogicalFunction.hpp new file mode 100644 index 0000000000..e3898c52ed --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulTnumberTnumberLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event mul_tnumber_tnumber: element-wise multiplication of two single-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_tnumber_tnumber`. Takes (value1:FLOAT64, value2:FLOAT64, ts:UINT64), + * constructs two co-instant temporals, applies the multiplication, and returns FLOAT64. + */ +class MulTnumberTnumberLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulTnumberTnumber"; + + MulTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/SubTnumberTnumberLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubTnumberTnumberLogicalFunction.hpp new file mode 100644 index 0000000000..94891a2836 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubTnumberTnumberLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event sub_tnumber_tnumber: element-wise subtraction of two single-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_tnumber_tnumber`. Takes (value1:FLOAT64, value2:FLOAT64, ts:UINT64), + * constructs two co-instant temporals, applies the subtraction, and returns FLOAT64. + */ +class SubTnumberTnumberLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubTnumberTnumber"; + + SubTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AddTnumberTnumberLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddTnumberTnumberLogicalFunction.cpp new file mode 100644 index 0000000000..223f155801 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddTnumberTnumberLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +AddTnumberTnumberLogicalFunction::AddTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value1)); + parameters.push_back(std::move(value2)); + parameters.push_back(std::move(ts)); +} + +DataType AddTnumberTnumberLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddTnumberTnumberLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddTnumberTnumberLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddTnumberTnumberLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddTnumberTnumberLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddTnumberTnumberLogicalFunction::getType() const { return NAME; } + +bool AddTnumberTnumberLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddTnumberTnumberLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction AddTnumberTnumberLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction AddTnumberTnumberLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterAddTnumberTnumberLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddTnumberTnumberLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return AddTnumberTnumberLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 1f40833d3b..c2debfca0e 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -25,6 +25,10 @@ add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalF add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) +add_plugin(AddTnumberTnumber LogicalFunction nes-logical-operators AddTnumberTnumberLogicalFunction.cpp) +add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) +add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnumberLogicalFunction.cpp) +add_plugin(SubTnumberTnumber LogicalFunction nes-logical-operators SubTnumberTnumberLogicalFunction.cpp) add_plugin(DivTfloatFloat LogicalFunction nes-logical-operators DivTfloatFloatLogicalFunction.cpp) add_plugin(MulTfloatFloat LogicalFunction nes-logical-operators MulTfloatFloatLogicalFunction.cpp) add_plugin(SubTfloatFloat LogicalFunction nes-logical-operators SubTfloatFloatLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/DivTnumberTnumberLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivTnumberTnumberLogicalFunction.cpp new file mode 100644 index 0000000000..fc7b32aa87 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivTnumberTnumberLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +DivTnumberTnumberLogicalFunction::DivTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value1)); + parameters.push_back(std::move(value2)); + parameters.push_back(std::move(ts)); +} + +DataType DivTnumberTnumberLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivTnumberTnumberLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivTnumberTnumberLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivTnumberTnumberLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivTnumberTnumberLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivTnumberTnumberLogicalFunction::getType() const { return NAME; } + +bool DivTnumberTnumberLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivTnumberTnumberLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction DivTnumberTnumberLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction DivTnumberTnumberLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterDivTnumberTnumberLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivTnumberTnumberLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return DivTnumberTnumberLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulTnumberTnumberLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulTnumberTnumberLogicalFunction.cpp new file mode 100644 index 0000000000..9d5d5fa562 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulTnumberTnumberLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +MulTnumberTnumberLogicalFunction::MulTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value1)); + parameters.push_back(std::move(value2)); + parameters.push_back(std::move(ts)); +} + +DataType MulTnumberTnumberLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulTnumberTnumberLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulTnumberTnumberLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulTnumberTnumberLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulTnumberTnumberLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulTnumberTnumberLogicalFunction::getType() const { return NAME; } + +bool MulTnumberTnumberLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulTnumberTnumberLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction MulTnumberTnumberLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction MulTnumberTnumberLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterMulTnumberTnumberLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulTnumberTnumberLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return MulTnumberTnumberLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubTnumberTnumberLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubTnumberTnumberLogicalFunction.cpp new file mode 100644 index 0000000000..844fe38ede --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubTnumberTnumberLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +SubTnumberTnumberLogicalFunction::SubTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value1)); + parameters.push_back(std::move(value2)); + parameters.push_back(std::move(ts)); +} + +DataType SubTnumberTnumberLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubTnumberTnumberLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubTnumberTnumberLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubTnumberTnumberLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubTnumberTnumberLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubTnumberTnumberLogicalFunction::getType() const { return NAME; } + +bool SubTnumberTnumberLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubTnumberTnumberLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction SubTnumberTnumberLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction SubTnumberTnumberLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterSubTnumberTnumberLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubTnumberTnumberLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return SubTnumberTnumberLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddTnumberTnumberPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddTnumberTnumberPhysicalFunction.hpp new file mode 100644 index 0000000000..c45dd431d3 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddTnumberTnumberPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `add_tnumber_tnumber`. + * + * Per-event element-wise addition of two co-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddTnumberTnumberPhysicalFunction : public PhysicalFunctionConcept { +public: + AddTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/DivTnumberTnumberPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivTnumberTnumberPhysicalFunction.hpp new file mode 100644 index 0000000000..3fde0ad5da --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivTnumberTnumberPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `div_tnumber_tnumber`. + * + * Per-event element-wise division of two co-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivTnumberTnumberPhysicalFunction : public PhysicalFunctionConcept { +public: + DivTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/MulTnumberTnumberPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulTnumberTnumberPhysicalFunction.hpp new file mode 100644 index 0000000000..f3b4af1bcf --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulTnumberTnumberPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `mul_tnumber_tnumber`. + * + * Per-event element-wise multiplication of two co-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulTnumberTnumberPhysicalFunction : public PhysicalFunctionConcept { +public: + MulTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/SubTnumberTnumberPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubTnumberTnumberPhysicalFunction.hpp new file mode 100644 index 0000000000..8e411da16d --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubTnumberTnumberPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `sub_tnumber_tnumber`. + * + * Per-event element-wise subtraction of two co-instant tnumbers. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubTnumberTnumberPhysicalFunction : public PhysicalFunctionConcept { +public: + SubTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AddTnumberTnumberPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddTnumberTnumberPhysicalFunction.cpp new file mode 100644 index 0000000000..6f709c0ceb --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddTnumberTnumberPhysicalFunction.cpp @@ -0,0 +1,94 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +AddTnumberTnumberPhysicalFunction::AddTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(value1Function)); + parameterFunctions.push_back(std::move(value2Function)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AddTnumberTnumberPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value1 = parameterValues[0].cast>(); + auto value2 = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value1, double value2, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + const std::string tsStr = MEOS::Meos::convertEpochToTimestamp(ts); + std::string wkt1 = fmt::format("{}@{}", value1, tsStr); + std::string wkt2 = fmt::format("{}@{}", value2, tsStr); + Temporal* t1 = tfloat_in(wkt1.c_str()); + Temporal* t2 = tfloat_in(wkt2.c_str()); + if (!t1 || !t2) { free(t1); free(t2); return 0.0; } + Temporal* res = add_tnumber_tnumber(t1, t2); + free(t1); free(t2); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value1, value2, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddTnumberTnumberPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddTnumberTnumberPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return AddTnumberTnumberPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index fcfbe5b9ba..de2aeb2de3 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -24,6 +24,10 @@ add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysic add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) +add_plugin(AddTnumberTnumber PhysicalFunction nes-physical-operators AddTnumberTnumberPhysicalFunction.cpp) +add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) +add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberTnumberPhysicalFunction.cpp) +add_plugin(SubTnumberTnumber PhysicalFunction nes-physical-operators SubTnumberTnumberPhysicalFunction.cpp) add_plugin(DivTfloatFloat PhysicalFunction nes-physical-operators DivTfloatFloatPhysicalFunction.cpp) add_plugin(MulTfloatFloat PhysicalFunction nes-physical-operators MulTfloatFloatPhysicalFunction.cpp) add_plugin(SubTfloatFloat PhysicalFunction nes-physical-operators SubTfloatFloatPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/DivTnumberTnumberPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivTnumberTnumberPhysicalFunction.cpp new file mode 100644 index 0000000000..1cab4168d2 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivTnumberTnumberPhysicalFunction.cpp @@ -0,0 +1,94 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +DivTnumberTnumberPhysicalFunction::DivTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(value1Function)); + parameterFunctions.push_back(std::move(value2Function)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal DivTnumberTnumberPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value1 = parameterValues[0].cast>(); + auto value2 = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value1, double value2, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + const std::string tsStr = MEOS::Meos::convertEpochToTimestamp(ts); + std::string wkt1 = fmt::format("{}@{}", value1, tsStr); + std::string wkt2 = fmt::format("{}@{}", value2, tsStr); + Temporal* t1 = tfloat_in(wkt1.c_str()); + Temporal* t2 = tfloat_in(wkt2.c_str()); + if (!t1 || !t2) { free(t1); free(t2); return 0.0; } + Temporal* res = div_tnumber_tnumber(t1, t2); + free(t1); free(t2); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value1, value2, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivTnumberTnumberPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivTnumberTnumberPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return DivTnumberTnumberPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulTnumberTnumberPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulTnumberTnumberPhysicalFunction.cpp new file mode 100644 index 0000000000..30f600c42b --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulTnumberTnumberPhysicalFunction.cpp @@ -0,0 +1,94 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +MulTnumberTnumberPhysicalFunction::MulTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(value1Function)); + parameterFunctions.push_back(std::move(value2Function)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal MulTnumberTnumberPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value1 = parameterValues[0].cast>(); + auto value2 = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value1, double value2, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + const std::string tsStr = MEOS::Meos::convertEpochToTimestamp(ts); + std::string wkt1 = fmt::format("{}@{}", value1, tsStr); + std::string wkt2 = fmt::format("{}@{}", value2, tsStr); + Temporal* t1 = tfloat_in(wkt1.c_str()); + Temporal* t2 = tfloat_in(wkt2.c_str()); + if (!t1 || !t2) { free(t1); free(t2); return 0.0; } + Temporal* res = mul_tnumber_tnumber(t1, t2); + free(t1); free(t2); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value1, value2, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulTnumberTnumberPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulTnumberTnumberPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return MulTnumberTnumberPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubTnumberTnumberPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubTnumberTnumberPhysicalFunction.cpp new file mode 100644 index 0000000000..4c57908824 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubTnumberTnumberPhysicalFunction.cpp @@ -0,0 +1,94 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +SubTnumberTnumberPhysicalFunction::SubTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(value1Function)); + parameterFunctions.push_back(std::move(value2Function)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal SubTnumberTnumberPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value1 = parameterValues[0].cast>(); + auto value2 = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value1, double value2, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + const std::string tsStr = MEOS::Meos::convertEpochToTimestamp(ts); + std::string wkt1 = fmt::format("{}@{}", value1, tsStr); + std::string wkt2 = fmt::format("{}@{}", value2, tsStr); + Temporal* t1 = tfloat_in(wkt1.c_str()); + Temporal* t2 = tfloat_in(wkt2.c_str()); + if (!t1 || !t2) { free(t1); free(t2); return 0.0; } + Temporal* res = sub_tnumber_tnumber(t1, t2); + free(t1); free(t2); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value1, value2, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubTnumberTnumberPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubTnumberTnumberPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return SubTnumberTnumberPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 893cd4b5d3..379cf86cd1 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | DIV_TFLOAT_FLOAT | MUL_TFLOAT_FLOAT | SUB_TFLOAT_FLOAT | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TNUMBER_TNUMBER | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -489,9 +489,13 @@ TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; ADD_TFLOAT_FLOAT: 'ADD_TFLOAT_FLOAT' | 'add_tfloat_float'; +ADD_TNUMBER_TNUMBER: 'ADD_TNUMBER_TNUMBER' | 'add_tnumber_tnumber'; DIV_TFLOAT_FLOAT: 'DIV_TFLOAT_FLOAT' | 'div_tfloat_float'; +DIV_TNUMBER_TNUMBER: 'DIV_TNUMBER_TNUMBER' | 'div_tnumber_tnumber'; MUL_TFLOAT_FLOAT: 'MUL_TFLOAT_FLOAT' | 'mul_tfloat_float'; +MUL_TNUMBER_TNUMBER: 'MUL_TNUMBER_TNUMBER' | 'mul_tnumber_tnumber'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; +SUB_TNUMBER_TNUMBER: 'SUB_TNUMBER_TNUMBER' | 'sub_tnumber_tnumber'; TFLOAT_CEIL: 'TFLOAT_CEIL' | 'tfloat_ceil'; TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 6fc7f008dc..8af91b5966 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -70,9 +70,13 @@ #include #include #include +#include #include +#include #include +#include #include +#include #include #include #include @@ -1630,6 +1634,122 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ADD_TNUMBER_TNUMBER */ + case AntlrSQLLexer::ADD_TNUMBER_TNUMBER: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_TNUMBER_TNUMBER requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(AddTnumberTnumberLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_TNUMBER_TNUMBER */ + /* BEGIN CODEGEN PARSER GLUE: DIV_TNUMBER_TNUMBER */ + case AntlrSQLLexer::DIV_TNUMBER_TNUMBER: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_TNUMBER_TNUMBER requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(DivTnumberTnumberLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_TNUMBER_TNUMBER */ + /* BEGIN CODEGEN PARSER GLUE: MUL_TNUMBER_TNUMBER */ + case AntlrSQLLexer::MUL_TNUMBER_TNUMBER: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_TNUMBER_TNUMBER requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(MulTnumberTnumberLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_TNUMBER_TNUMBER */ + /* BEGIN CODEGEN PARSER GLUE: SUB_TNUMBER_TNUMBER */ + case AntlrSQLLexer::SUB_TNUMBER_TNUMBER: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_TNUMBER_TNUMBER requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(SubTnumberTnumberLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_TNUMBER_TNUMBER */ default: /// Check if the function is a constructor for a datatype From 69172abb64d87bcdeb9f200768bafb5aed4f0945 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 05:52:35 +0200 Subject: [PATCH 08/12] feat(meos): add TEMPORAL_ROUND, TDISTANCE_TFLOAT_FLOAT, TDISTANCE_TNUMBER_TNUMBER NES operators (W50) Adds per-event NES operators backed by temporal_round (3-arg: value, ts, maxdd), tdistance_tfloat_float (3-arg: value, ts, d), and tdistance_tnumber_tnumber (3-arg: value1, value2, ts). Each operator constructs one or two co-instant tfloats, applies the MEOS function, and returns the resulting double. Logical/physical function pairs, plugin registrations, grammar tokens, and parser case blocks are included. --- .../TdistanceTfloatFloatLogicalFunction.hpp | 54 +++++++++ ...TdistanceTnumberTnumberLogicalFunction.hpp | 54 +++++++++ .../Meos/TemporalRoundLogicalFunction.hpp | 54 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../TdistanceTfloatFloatLogicalFunction.cpp | 105 ++++++++++++++++++ ...TdistanceTnumberTnumberLogicalFunction.cpp | 105 ++++++++++++++++++ .../Meos/TemporalRoundLogicalFunction.cpp | 105 ++++++++++++++++++ .../TdistanceTfloatFloatPhysicalFunction.hpp | 43 +++++++ ...distanceTnumberTnumberPhysicalFunction.hpp | 43 +++++++ .../Meos/TemporalRoundPhysicalFunction.hpp | 43 +++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../TdistanceTfloatFloatPhysicalFunction.cpp | 91 +++++++++++++++ ...distanceTnumberTnumberPhysicalFunction.cpp | 94 ++++++++++++++++ .../Meos/TemporalRoundPhysicalFunction.cpp | 91 +++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 5 +- .../src/AntlrSQLQueryPlanCreator.cpp | 90 +++++++++++++++ 16 files changed, 982 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TdistanceTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TemporalRoundLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TdistanceTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TemporalRoundLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TemporalRoundPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TemporalRoundPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TdistanceTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TdistanceTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..0404bd65b5 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TdistanceTfloatFloatLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tdistance_tfloat_float: distance between a single-instant tfloat and a float. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tdistance_tfloat_float`. Takes (value:FLOAT64, ts:UINT64, d:FLOAT64), + * constructs a single-instant temporal, applies the distance function, and returns FLOAT64. + */ +class TdistanceTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TdistanceTfloatFloat"; + + TdistanceTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction d); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.hpp new file mode 100644 index 0000000000..1f9f544348 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tdistance_tnumber_tnumber: distance between two co-instant tnumber values. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tdistance_tnumber_tnumber`. Takes (value1:FLOAT64, value2:FLOAT64, ts:UINT64), + * constructs two co-instant temporals, applies the distance function, and returns FLOAT64. + */ +class TdistanceTnumberTnumberLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TdistanceTnumberTnumber"; + + TdistanceTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TemporalRoundLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TemporalRoundLogicalFunction.hpp new file mode 100644 index 0000000000..987761a0df --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TemporalRoundLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event temporal_round: rounds a single-instant tfloat to N decimal places. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `temporal_round`. Takes (value:FLOAT64, ts:UINT64, maxdd:FLOAT64→int), + * constructs a single-instant temporal, applies the rounding, and returns FLOAT64. + */ +class TemporalRoundLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TemporalRound"; + + TemporalRoundLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction maxdd); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index c2debfca0e..a58cf4184b 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -26,6 +26,9 @@ add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogi add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) add_plugin(AddTnumberTnumber LogicalFunction nes-logical-operators AddTnumberTnumberLogicalFunction.cpp) +add_plugin(TdistanceTfloatFloat LogicalFunction nes-logical-operators TdistanceTfloatFloatLogicalFunction.cpp) +add_plugin(TdistanceTnumberTnumber LogicalFunction nes-logical-operators TdistanceTnumberTnumberLogicalFunction.cpp) +add_plugin(TemporalRound LogicalFunction nes-logical-operators TemporalRoundLogicalFunction.cpp) add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnumberLogicalFunction.cpp) add_plugin(SubTnumberTnumber LogicalFunction nes-logical-operators SubTnumberTnumberLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TdistanceTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TdistanceTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..3532410708 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TdistanceTfloatFloatLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TdistanceTfloatFloatLogicalFunction::TdistanceTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction d) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(d)); +} + +DataType TdistanceTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TdistanceTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TdistanceTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TdistanceTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TdistanceTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TdistanceTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool TdistanceTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TdistanceTfloatFloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TdistanceTfloatFloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TdistanceTfloatFloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTdistanceTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TdistanceTfloatFloatLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TdistanceTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.cpp new file mode 100644 index 0000000000..2ff41374c1 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TdistanceTnumberTnumberLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TdistanceTnumberTnumberLogicalFunction::TdistanceTnumberTnumberLogicalFunction(LogicalFunction value1, + LogicalFunction value2, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value1)); + parameters.push_back(std::move(value2)); + parameters.push_back(std::move(ts)); +} + +DataType TdistanceTnumberTnumberLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TdistanceTnumberTnumberLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TdistanceTnumberTnumberLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TdistanceTnumberTnumberLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TdistanceTnumberTnumberLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TdistanceTnumberTnumberLogicalFunction::getType() const { return NAME; } + +bool TdistanceTnumberTnumberLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TdistanceTnumberTnumberLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TdistanceTnumberTnumberLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TdistanceTnumberTnumberLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTdistanceTnumberTnumberLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TdistanceTnumberTnumberLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TdistanceTnumberTnumberLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TemporalRoundLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TemporalRoundLogicalFunction.cpp new file mode 100644 index 0000000000..95163814fd --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TemporalRoundLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TemporalRoundLogicalFunction::TemporalRoundLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction maxdd) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(maxdd)); +} + +DataType TemporalRoundLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TemporalRoundLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TemporalRoundLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TemporalRoundLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TemporalRoundLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TemporalRoundLogicalFunction::getType() const { return NAME; } + +bool TemporalRoundLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TemporalRoundLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TemporalRoundLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TemporalRoundLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTemporalRoundLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TemporalRoundLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TemporalRoundLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..06bf692313 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tdistance_tfloat_float`. + * + * Per-event tdistance_tfloat_float: distance between a single-instant tfloat and a float. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TdistanceTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + TdistanceTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction dFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.hpp new file mode 100644 index 0000000000..107d00bae1 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tdistance_tnumber_tnumber`. + * + * Per-event tdistance_tnumber_tnumber: distance between two co-instant tnumber values. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TdistanceTnumberTnumberPhysicalFunction : public PhysicalFunctionConcept { +public: + TdistanceTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TemporalRoundPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TemporalRoundPhysicalFunction.hpp new file mode 100644 index 0000000000..4b169faee3 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TemporalRoundPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `temporal_round`. + * + * Per-event temporal_round: rounds a single-instant tfloat to N decimal places. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TemporalRoundPhysicalFunction : public PhysicalFunctionConcept { +public: + TemporalRoundPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction maxddFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index de2aeb2de3..d3c9c131b4 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -25,6 +25,9 @@ add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPh add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) add_plugin(AddTnumberTnumber PhysicalFunction nes-physical-operators AddTnumberTnumberPhysicalFunction.cpp) +add_plugin(TdistanceTfloatFloat PhysicalFunction nes-physical-operators TdistanceTfloatFloatPhysicalFunction.cpp) +add_plugin(TdistanceTnumberTnumber PhysicalFunction nes-physical-operators TdistanceTnumberTnumberPhysicalFunction.cpp) +add_plugin(TemporalRound PhysicalFunction nes-physical-operators TemporalRoundPhysicalFunction.cpp) add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberTnumberPhysicalFunction.cpp) add_plugin(SubTnumberTnumber PhysicalFunction nes-physical-operators SubTnumberTnumberPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..f32584b1fc --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TdistanceTfloatFloatPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TdistanceTfloatFloatPhysicalFunction::TdistanceTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction dFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(dFunction)); +} + +VarVal TdistanceTfloatFloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto d = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tdistance_tfloat_float(temp, d); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, d); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTdistanceTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TdistanceTfloatFloatPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TdistanceTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.cpp new file mode 100644 index 0000000000..26696f4bb7 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TdistanceTnumberTnumberPhysicalFunction.cpp @@ -0,0 +1,94 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TdistanceTnumberTnumberPhysicalFunction::TdistanceTnumberTnumberPhysicalFunction(PhysicalFunction value1Function, + PhysicalFunction value2Function, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(value1Function)); + parameterFunctions.push_back(std::move(value2Function)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TdistanceTnumberTnumberPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value1 = parameterValues[0].cast>(); + auto value2 = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value1, double value2, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + const std::string tsStr = MEOS::Meos::convertEpochToTimestamp(ts); + std::string wkt1 = fmt::format("{}@{}", value1, tsStr); + std::string wkt2 = fmt::format("{}@{}", value2, tsStr); + Temporal* t1 = tfloat_in(wkt1.c_str()); + Temporal* t2 = tfloat_in(wkt2.c_str()); + if (!t1 || !t2) { free(t1); free(t2); return 0.0; } + Temporal* res = tdistance_tnumber_tnumber(t1, t2); + free(t1); free(t2); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value1, value2, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTdistanceTnumberTnumberPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TdistanceTnumberTnumberPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TdistanceTnumberTnumberPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TemporalRoundPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TemporalRoundPhysicalFunction.cpp new file mode 100644 index 0000000000..8836fe5bdf --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TemporalRoundPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TemporalRoundPhysicalFunction::TemporalRoundPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction maxddFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(maxddFunction)); +} + +VarVal TemporalRoundPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto maxdd = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double maxdd_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = temporal_round(temp, static_cast(maxdd_d)); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, maxdd); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTemporalRoundPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TemporalRoundPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TemporalRoundPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 379cf86cd1..f4fd7a6858 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TNUMBER_TNUMBER | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -496,6 +496,9 @@ MUL_TFLOAT_FLOAT: 'MUL_TFLOAT_FLOAT' | 'mul_tfloat_float'; MUL_TNUMBER_TNUMBER: 'MUL_TNUMBER_TNUMBER' | 'mul_tnumber_tnumber'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; SUB_TNUMBER_TNUMBER: 'SUB_TNUMBER_TNUMBER' | 'sub_tnumber_tnumber'; +TDISTANCE_TFLOAT_FLOAT: 'TDISTANCE_TFLOAT_FLOAT' | 'tdistance_tfloat_float'; +TDISTANCE_TNUMBER_TNUMBER: 'TDISTANCE_TNUMBER_TNUMBER' | 'tdistance_tnumber_tnumber'; +TEMPORAL_ROUND: 'TEMPORAL_ROUND' | 'temporal_round'; TFLOAT_CEIL: 'TFLOAT_CEIL' | 'tfloat_ceil'; TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 8af91b5966..de68032c01 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -77,6 +77,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1751,6 +1754,93 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont break; /* END CODEGEN PARSER GLUE: SUB_TNUMBER_TNUMBER */ + case AntlrSQLLexer::TDISTANCE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TDISTANCE_TFLOAT_FLOAT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TdistanceTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TDISTANCE_TFLOAT_FLOAT */ + + case AntlrSQLLexer::TDISTANCE_TNUMBER_TNUMBER: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TDISTANCE_TNUMBER_TNUMBER requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TdistanceTnumberTnumberLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TDISTANCE_TNUMBER_TNUMBER */ + + case AntlrSQLLexer::TEMPORAL_ROUND: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TEMPORAL_ROUND requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TemporalRoundLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TEMPORAL_ROUND */ + default: /// Check if the function is a constructor for a datatype if (const auto dataType = DataTypeProvider::tryProvideDataType(funcName); dataType.has_value()) From b789cafb8df066c736a178f512cc54143e85ee60 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 05:58:40 +0200 Subject: [PATCH 09/12] feat(meos): add ADD/SUB/MUL/DIV_TINT_INT NES operators (W51) Adds per-event NES operators backed by add_tint_int, sub_tint_int, mul_tint_int, and div_tint_int (3-arg each: value, ts, scalar_int). Each operator constructs a single-instant tint, applies the MEOS integer arithmetic function, and returns the resulting integer as FLOAT64. Logical/physical function pairs, plugin registrations, grammar tokens, and parser case blocks are included. --- .../Meos/AddTintIntLogicalFunction.hpp | 54 ++++++++ .../Meos/DivTintIntLogicalFunction.hpp | 54 ++++++++ .../Meos/MulTintIntLogicalFunction.hpp | 54 ++++++++ .../Meos/SubTintIntLogicalFunction.hpp | 54 ++++++++ .../Meos/AddTintIntLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTintIntLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulTintIntLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubTintIntLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/AddTintIntPhysicalFunction.hpp | 43 +++++++ .../Meos/DivTintIntPhysicalFunction.hpp | 43 +++++++ .../Meos/MulTintIntPhysicalFunction.hpp | 43 +++++++ .../Meos/SubTintIntPhysicalFunction.hpp | 43 +++++++ .../Meos/AddTintIntPhysicalFunction.cpp | 91 +++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTintIntPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/MulTintIntPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/SubTintIntPhysicalFunction.cpp | 91 +++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 121 ++++++++++++++++++ 20 files changed, 1306 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/AddTintIntLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivTintIntLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulTintIntLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubTintIntLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddTintIntLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivTintIntLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulTintIntLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubTintIntLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddTintIntPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivTintIntPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulTintIntPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubTintIntPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddTintIntPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivTintIntPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulTintIntPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubTintIntPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddTintIntLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddTintIntLogicalFunction.hpp new file mode 100644 index 0000000000..c38de2cff9 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddTintIntLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event add_tint_int: adds a constant integer to a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_tint_int`. Takes (value:FLOAT64, ts:UINT64, addend:FLOAT64→int), + * constructs a single-instant temporal, applies the addition, and returns FLOAT64. + */ +class AddTintIntLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddTintInt"; + + AddTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction addend); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/DivTintIntLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivTintIntLogicalFunction.hpp new file mode 100644 index 0000000000..3c201c5b16 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivTintIntLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event div_tint_int: divides a single-instant tint value by a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_tint_int`. Takes (value:FLOAT64, ts:UINT64, divisor:FLOAT64→int), + * constructs a single-instant temporal, applies the division, and returns FLOAT64. + */ +class DivTintIntLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivTintInt"; + + DivTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction divisor); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/MulTintIntLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulTintIntLogicalFunction.hpp new file mode 100644 index 0000000000..bf2fbb90b5 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulTintIntLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event mul_tint_int: multiplies a single-instant tint value by a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_tint_int`. Takes (value:FLOAT64, ts:UINT64, multiplier:FLOAT64→int), + * constructs a single-instant temporal, applies the multiplication, and returns FLOAT64. + */ +class MulTintIntLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulTintInt"; + + MulTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction multiplier); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/SubTintIntLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubTintIntLogicalFunction.hpp new file mode 100644 index 0000000000..49c77fc4d3 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubTintIntLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event sub_tint_int: subtracts a constant integer from a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_tint_int`. Takes (value:FLOAT64, ts:UINT64, subtrahend:FLOAT64→int), + * constructs a single-instant temporal, applies the subtraction, and returns FLOAT64. + */ +class SubTintIntLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubTintInt"; + + SubTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction subtrahend); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AddTintIntLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddTintIntLogicalFunction.cpp new file mode 100644 index 0000000000..a788921856 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddTintIntLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +AddTintIntLogicalFunction::AddTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction addend) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(addend)); +} + +DataType AddTintIntLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddTintIntLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddTintIntLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddTintIntLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddTintIntLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddTintIntLogicalFunction::getType() const { return NAME; } + +bool AddTintIntLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddTintIntLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction AddTintIntLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction AddTintIntLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterAddTintIntLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddTintIntLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return AddTintIntLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index a58cf4184b..5734d5a728 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -25,12 +25,16 @@ add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalF add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) +add_plugin(AddTintInt LogicalFunction nes-logical-operators AddTintIntLogicalFunction.cpp) add_plugin(AddTnumberTnumber LogicalFunction nes-logical-operators AddTnumberTnumberLogicalFunction.cpp) add_plugin(TdistanceTfloatFloat LogicalFunction nes-logical-operators TdistanceTfloatFloatLogicalFunction.cpp) add_plugin(TdistanceTnumberTnumber LogicalFunction nes-logical-operators TdistanceTnumberTnumberLogicalFunction.cpp) add_plugin(TemporalRound LogicalFunction nes-logical-operators TemporalRoundLogicalFunction.cpp) +add_plugin(DivTintInt LogicalFunction nes-logical-operators DivTintIntLogicalFunction.cpp) add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) +add_plugin(MulTintInt LogicalFunction nes-logical-operators MulTintIntLogicalFunction.cpp) add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnumberLogicalFunction.cpp) +add_plugin(SubTintInt LogicalFunction nes-logical-operators SubTintIntLogicalFunction.cpp) add_plugin(SubTnumberTnumber LogicalFunction nes-logical-operators SubTnumberTnumberLogicalFunction.cpp) add_plugin(DivTfloatFloat LogicalFunction nes-logical-operators DivTfloatFloatLogicalFunction.cpp) add_plugin(MulTfloatFloat LogicalFunction nes-logical-operators MulTfloatFloatLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/DivTintIntLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivTintIntLogicalFunction.cpp new file mode 100644 index 0000000000..723116937f --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivTintIntLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +DivTintIntLogicalFunction::DivTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction divisor) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(divisor)); +} + +DataType DivTintIntLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivTintIntLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivTintIntLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivTintIntLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivTintIntLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivTintIntLogicalFunction::getType() const { return NAME; } + +bool DivTintIntLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivTintIntLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction DivTintIntLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction DivTintIntLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterDivTintIntLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivTintIntLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return DivTintIntLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulTintIntLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulTintIntLogicalFunction.cpp new file mode 100644 index 0000000000..e973fe3aa8 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulTintIntLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +MulTintIntLogicalFunction::MulTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction multiplier) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(multiplier)); +} + +DataType MulTintIntLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulTintIntLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulTintIntLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulTintIntLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulTintIntLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulTintIntLogicalFunction::getType() const { return NAME; } + +bool MulTintIntLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulTintIntLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction MulTintIntLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction MulTintIntLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterMulTintIntLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulTintIntLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return MulTintIntLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubTintIntLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubTintIntLogicalFunction.cpp new file mode 100644 index 0000000000..1b18e51bce --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubTintIntLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +SubTintIntLogicalFunction::SubTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction subtrahend) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(subtrahend)); +} + +DataType SubTintIntLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubTintIntLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubTintIntLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubTintIntLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubTintIntLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubTintIntLogicalFunction::getType() const { return NAME; } + +bool SubTintIntLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubTintIntLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction SubTintIntLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction SubTintIntLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterSubTintIntLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubTintIntLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return SubTintIntLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddTintIntPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddTintIntPhysicalFunction.hpp new file mode 100644 index 0000000000..e2fd8daba7 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddTintIntPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `add_tint_int`. + * + * Per-event add_tint_int: adds a constant integer to a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddTintIntPhysicalFunction : public PhysicalFunctionConcept { +public: + AddTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction addendFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/DivTintIntPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivTintIntPhysicalFunction.hpp new file mode 100644 index 0000000000..40c7f5a1a3 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivTintIntPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `div_tint_int`. + * + * Per-event div_tint_int: divides a single-instant tint value by a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivTintIntPhysicalFunction : public PhysicalFunctionConcept { +public: + DivTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction divisorFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/MulTintIntPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulTintIntPhysicalFunction.hpp new file mode 100644 index 0000000000..8f3215281f --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulTintIntPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `mul_tint_int`. + * + * Per-event mul_tint_int: multiplies a single-instant tint value by a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulTintIntPhysicalFunction : public PhysicalFunctionConcept { +public: + MulTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction multiplierFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/SubTintIntPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubTintIntPhysicalFunction.hpp new file mode 100644 index 0000000000..d7792e3f00 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubTintIntPhysicalFunction.hpp @@ -0,0 +1,43 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `sub_tint_int`. + * + * Per-event sub_tint_int: subtracts a constant integer from a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubTintIntPhysicalFunction : public PhysicalFunctionConcept { +public: + SubTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction subtrahendFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AddTintIntPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddTintIntPhysicalFunction.cpp new file mode 100644 index 0000000000..031a677e61 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddTintIntPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +AddTintIntPhysicalFunction::AddTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction addendFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(addendFunction)); +} + +VarVal AddTintIntPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto addend = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double addend_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = add_tint_int(temp, static_cast(addend_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, addend); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddTintIntPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddTintIntPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return AddTintIntPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index d3c9c131b4..1b7168a2c2 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -24,12 +24,16 @@ add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysic add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) +add_plugin(AddTintInt PhysicalFunction nes-physical-operators AddTintIntPhysicalFunction.cpp) add_plugin(AddTnumberTnumber PhysicalFunction nes-physical-operators AddTnumberTnumberPhysicalFunction.cpp) add_plugin(TdistanceTfloatFloat PhysicalFunction nes-physical-operators TdistanceTfloatFloatPhysicalFunction.cpp) add_plugin(TdistanceTnumberTnumber PhysicalFunction nes-physical-operators TdistanceTnumberTnumberPhysicalFunction.cpp) add_plugin(TemporalRound PhysicalFunction nes-physical-operators TemporalRoundPhysicalFunction.cpp) +add_plugin(DivTintInt PhysicalFunction nes-physical-operators DivTintIntPhysicalFunction.cpp) add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) +add_plugin(MulTintInt PhysicalFunction nes-physical-operators MulTintIntPhysicalFunction.cpp) add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberTnumberPhysicalFunction.cpp) +add_plugin(SubTintInt PhysicalFunction nes-physical-operators SubTintIntPhysicalFunction.cpp) add_plugin(SubTnumberTnumber PhysicalFunction nes-physical-operators SubTnumberTnumberPhysicalFunction.cpp) add_plugin(DivTfloatFloat PhysicalFunction nes-physical-operators DivTfloatFloatPhysicalFunction.cpp) add_plugin(MulTfloatFloat PhysicalFunction nes-physical-operators MulTfloatFloatPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/DivTintIntPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivTintIntPhysicalFunction.cpp new file mode 100644 index 0000000000..540c8b52e3 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivTintIntPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +DivTintIntPhysicalFunction::DivTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction divisorFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(divisorFunction)); +} + +VarVal DivTintIntPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto divisor = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double divisor_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = div_tint_int(temp, static_cast(divisor_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, divisor); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivTintIntPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivTintIntPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return DivTintIntPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulTintIntPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulTintIntPhysicalFunction.cpp new file mode 100644 index 0000000000..18b90450ae --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulTintIntPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +MulTintIntPhysicalFunction::MulTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction multiplierFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(multiplierFunction)); +} + +VarVal MulTintIntPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto multiplier = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double multiplier_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = mul_tint_int(temp, static_cast(multiplier_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, multiplier); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulTintIntPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulTintIntPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return MulTintIntPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubTintIntPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubTintIntPhysicalFunction.cpp new file mode 100644 index 0000000000..c086705591 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubTintIntPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +SubTintIntPhysicalFunction::SubTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction subtrahendFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(subtrahendFunction)); +} + +VarVal SubTintIntPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto subtrahend = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double subtrahend_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = sub_tint_int(temp, static_cast(subtrahend_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, subtrahend); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubTintIntPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubTintIntPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return SubTintIntPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index f4fd7a6858..f41484aa70 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -489,12 +489,16 @@ TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; ADD_TFLOAT_FLOAT: 'ADD_TFLOAT_FLOAT' | 'add_tfloat_float'; +ADD_TINT_INT: 'ADD_TINT_INT' | 'add_tint_int'; ADD_TNUMBER_TNUMBER: 'ADD_TNUMBER_TNUMBER' | 'add_tnumber_tnumber'; DIV_TFLOAT_FLOAT: 'DIV_TFLOAT_FLOAT' | 'div_tfloat_float'; +DIV_TINT_INT: 'DIV_TINT_INT' | 'div_tint_int'; DIV_TNUMBER_TNUMBER: 'DIV_TNUMBER_TNUMBER' | 'div_tnumber_tnumber'; MUL_TFLOAT_FLOAT: 'MUL_TFLOAT_FLOAT' | 'mul_tfloat_float'; +MUL_TINT_INT: 'MUL_TINT_INT' | 'mul_tint_int'; MUL_TNUMBER_TNUMBER: 'MUL_TNUMBER_TNUMBER' | 'mul_tnumber_tnumber'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; +SUB_TINT_INT: 'SUB_TINT_INT' | 'sub_tint_int'; SUB_TNUMBER_TNUMBER: 'SUB_TNUMBER_TNUMBER' | 'sub_tnumber_tnumber'; TDISTANCE_TFLOAT_FLOAT: 'TDISTANCE_TFLOAT_FLOAT' | 'tdistance_tfloat_float'; TDISTANCE_TNUMBER_TNUMBER: 'TDISTANCE_TNUMBER_TNUMBER' | 'tdistance_tnumber_tnumber'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index de68032c01..0ed1f77265 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -70,12 +70,16 @@ #include #include #include +#include #include #include +#include #include #include +#include #include #include +#include #include #include #include @@ -1637,6 +1641,123 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ + + case AntlrSQLLexer::ADD_TINT_INT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_TINT_INT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(AddTintIntLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_TINT_INT */ + + case AntlrSQLLexer::DIV_TINT_INT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_TINT_INT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(DivTintIntLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_TINT_INT */ + + case AntlrSQLLexer::MUL_TINT_INT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_TINT_INT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(MulTintIntLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_TINT_INT */ + + case AntlrSQLLexer::SUB_TINT_INT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_TINT_INT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(SubTintIntLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: ADD_TNUMBER_TNUMBER */ case AntlrSQLLexer::ADD_TNUMBER_TNUMBER: { From e64267ac6c6d0ee90bd167a1426e69f387a0784b Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:07:19 +0200 Subject: [PATCH 10/12] feat(meos): add TDISTANCE_TINT_INT, TINT_SHIFT_VALUE, TINT_SCALE_VALUE, TINT_SHIFT_SCALE_VALUE NES operators (W52) --- .../Meos/TdistanceTintIntLogicalFunction.hpp | 54 ++++++++ .../Meos/TintScaleValueLogicalFunction.hpp | 54 ++++++++ .../TintShiftScaleValueLogicalFunction.hpp | 55 ++++++++ .../Meos/TintShiftValueLogicalFunction.hpp | 54 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/TdistanceTintIntLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/TintScaleValueLogicalFunction.cpp | 105 +++++++++++++++ .../TintShiftScaleValueLogicalFunction.cpp | 108 ++++++++++++++++ .../Meos/TintShiftValueLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/TdistanceTintIntPhysicalFunction.hpp | 44 +++++++ .../Meos/TintScaleValuePhysicalFunction.hpp | 44 +++++++ .../TintShiftScaleValuePhysicalFunction.hpp | 45 +++++++ .../Meos/TintShiftValuePhysicalFunction.hpp | 44 +++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/TdistanceTintIntPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/TintScaleValuePhysicalFunction.cpp | 91 +++++++++++++ .../TintShiftScaleValuePhysicalFunction.cpp | 95 ++++++++++++++ .../Meos/TintShiftValuePhysicalFunction.cpp | 91 +++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 121 ++++++++++++++++++ 20 files changed, 1319 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TdistanceTintIntLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TintScaleValueLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TintShiftScaleValueLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TintShiftValueLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TdistanceTintIntLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TintScaleValueLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TintShiftScaleValueLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TintShiftValueLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TdistanceTintIntPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TintScaleValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TintShiftScaleValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TintShiftValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TdistanceTintIntPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TintScaleValuePhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TintShiftScaleValuePhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TintShiftValuePhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TdistanceTintIntLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TdistanceTintIntLogicalFunction.hpp new file mode 100644 index 0000000000..a8baa981f0 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TdistanceTintIntLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tdistance_tint_int: distance between a single-instant tint and an integer. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tdistance_tint_int`. Takes (value:FLOAT64, ts:UINT64, d:FLOAT64→int), + * constructs a single-instant temporal, applies the distance function, and returns FLOAT64. + */ +class TdistanceTintIntLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TdistanceTintInt"; + + TdistanceTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction d); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TintScaleValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TintScaleValueLogicalFunction.hpp new file mode 100644 index 0000000000..eaf261f031 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TintScaleValueLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tint_scale_value: scales a single-instant tint to a given width. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tint_scale_value`. Takes (value:FLOAT64, ts:UINT64, width:FLOAT64→int), + * constructs a single-instant temporal, applies the scale, and returns FLOAT64. + */ +class TintScaleValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TintScaleValue"; + + TintScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction width); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TintShiftScaleValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TintShiftScaleValueLogicalFunction.hpp new file mode 100644 index 0000000000..4b3ec6c91e --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TintShiftScaleValueLogicalFunction.hpp @@ -0,0 +1,55 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tint_shift_scale_value: shifts and scales a single-instant tint. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tint_shift_scale_value`. Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64→int, width:FLOAT64→int), + * constructs a single-instant temporal, applies the shift-and-scale, and returns FLOAT64. + */ +class TintShiftScaleValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TintShiftScaleValue"; + + TintShiftScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift, + LogicalFunction width); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TintShiftValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TintShiftValueLogicalFunction.hpp new file mode 100644 index 0000000000..ebf94d3dd8 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TintShiftValueLogicalFunction.hpp @@ -0,0 +1,54 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tint_shift_value: shifts a single-instant tint by a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tint_shift_value`. Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64→int), + * constructs a single-instant temporal, applies the shift, and returns FLOAT64. + */ +class TintShiftValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TintShiftValue"; + + TintShiftValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 5734d5a728..49cd3f9231 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -28,8 +28,12 @@ add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLo add_plugin(AddTintInt LogicalFunction nes-logical-operators AddTintIntLogicalFunction.cpp) add_plugin(AddTnumberTnumber LogicalFunction nes-logical-operators AddTnumberTnumberLogicalFunction.cpp) add_plugin(TdistanceTfloatFloat LogicalFunction nes-logical-operators TdistanceTfloatFloatLogicalFunction.cpp) +add_plugin(TdistanceTintInt LogicalFunction nes-logical-operators TdistanceTintIntLogicalFunction.cpp) add_plugin(TdistanceTnumberTnumber LogicalFunction nes-logical-operators TdistanceTnumberTnumberLogicalFunction.cpp) add_plugin(TemporalRound LogicalFunction nes-logical-operators TemporalRoundLogicalFunction.cpp) +add_plugin(TintScaleValue LogicalFunction nes-logical-operators TintScaleValueLogicalFunction.cpp) +add_plugin(TintShiftScaleValue LogicalFunction nes-logical-operators TintShiftScaleValueLogicalFunction.cpp) +add_plugin(TintShiftValue LogicalFunction nes-logical-operators TintShiftValueLogicalFunction.cpp) add_plugin(DivTintInt LogicalFunction nes-logical-operators DivTintIntLogicalFunction.cpp) add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) add_plugin(MulTintInt LogicalFunction nes-logical-operators MulTintIntLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TdistanceTintIntLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TdistanceTintIntLogicalFunction.cpp new file mode 100644 index 0000000000..01517365af --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TdistanceTintIntLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TdistanceTintIntLogicalFunction::TdistanceTintIntLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction d) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(d)); +} + +DataType TdistanceTintIntLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TdistanceTintIntLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TdistanceTintIntLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TdistanceTintIntLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TdistanceTintIntLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TdistanceTintIntLogicalFunction::getType() const { return NAME; } + +bool TdistanceTintIntLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TdistanceTintIntLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TdistanceTintIntLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TdistanceTintIntLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTdistanceTintIntLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TdistanceTintIntLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TdistanceTintIntLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TintScaleValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TintScaleValueLogicalFunction.cpp new file mode 100644 index 0000000000..d51aadcdef --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TintScaleValueLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TintScaleValueLogicalFunction::TintScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction width) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(width)); +} + +DataType TintScaleValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TintScaleValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TintScaleValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TintScaleValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TintScaleValueLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TintScaleValueLogicalFunction::getType() const { return NAME; } + +bool TintScaleValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TintScaleValueLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TintScaleValueLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TintScaleValueLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTintScaleValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TintScaleValueLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TintScaleValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TintShiftScaleValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TintShiftScaleValueLogicalFunction.cpp new file mode 100644 index 0000000000..b4096559fb --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TintShiftScaleValueLogicalFunction.cpp @@ -0,0 +1,108 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TintShiftScaleValueLogicalFunction::TintShiftScaleValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift, + LogicalFunction width) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(4); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(shift)); + parameters.push_back(std::move(width)); +} + +DataType TintShiftScaleValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TintShiftScaleValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TintShiftScaleValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TintShiftScaleValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 4, "TintShiftScaleValueLogicalFunction requires 4 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TintShiftScaleValueLogicalFunction::getType() const { return NAME; } + +bool TintShiftScaleValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TintShiftScaleValueLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TintShiftScaleValueLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TintShiftScaleValueLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTintShiftScaleValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 4, + "TintShiftScaleValueLogicalFunction requires 4 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + auto arg3 = std::move(arguments.children[3]); + return TintShiftScaleValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2), std::move(arg3)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TintShiftValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TintShiftValueLogicalFunction.cpp new file mode 100644 index 0000000000..c540e6ea81 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TintShiftValueLogicalFunction.cpp @@ -0,0 +1,105 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TintShiftValueLogicalFunction::TintShiftValueLogicalFunction(LogicalFunction value, + LogicalFunction ts, + LogicalFunction shift) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); + parameters.push_back(std::move(shift)); +} + +DataType TintShiftValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TintShiftValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TintShiftValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TintShiftValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TintShiftValueLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TintShiftValueLogicalFunction::getType() const { return NAME; } + +bool TintShiftValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TintShiftValueLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TintShiftValueLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TintShiftValueLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTintShiftValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TintShiftValueLogicalFunction requires 3 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + auto arg2 = std::move(arguments.children[2]); + return TintShiftValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TdistanceTintIntPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TdistanceTintIntPhysicalFunction.hpp new file mode 100644 index 0000000000..02d4ffe164 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TdistanceTintIntPhysicalFunction.hpp @@ -0,0 +1,44 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tdistance_tint_int`. + * + * Per-event tdistance_tint_int: computes the temporal distance between a + * single-instant tint value and a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TdistanceTintIntPhysicalFunction : public PhysicalFunctionConcept { +public: + TdistanceTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction dFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TintScaleValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TintScaleValuePhysicalFunction.hpp new file mode 100644 index 0000000000..e55e1d9ad3 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TintScaleValuePhysicalFunction.hpp @@ -0,0 +1,44 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tint_scale_value`. + * + * Per-event tint_scale_value: scales the value span of a single-instant tint + * to the given integer width. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TintScaleValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TintScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction widthFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TintShiftScaleValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TintShiftScaleValuePhysicalFunction.hpp new file mode 100644 index 0000000000..d6c7628c8c --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TintShiftScaleValuePhysicalFunction.hpp @@ -0,0 +1,45 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tint_shift_scale_value`. + * + * Per-event tint_shift_scale_value: shifts the value span of a single-instant + * tint by a constant integer and scales it to the given integer width. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TintShiftScaleValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TintShiftScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction, + PhysicalFunction widthFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TintShiftValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TintShiftValuePhysicalFunction.hpp new file mode 100644 index 0000000000..f12e6e7240 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TintShiftValuePhysicalFunction.hpp @@ -0,0 +1,44 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tint_shift_value`. + * + * Per-event tint_shift_value: shifts the value span of a single-instant tint + * by a constant integer. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TintShiftValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TintShiftValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index 1b7168a2c2..5138cf9b1d 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -27,8 +27,12 @@ add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloat add_plugin(AddTintInt PhysicalFunction nes-physical-operators AddTintIntPhysicalFunction.cpp) add_plugin(AddTnumberTnumber PhysicalFunction nes-physical-operators AddTnumberTnumberPhysicalFunction.cpp) add_plugin(TdistanceTfloatFloat PhysicalFunction nes-physical-operators TdistanceTfloatFloatPhysicalFunction.cpp) +add_plugin(TdistanceTintInt PhysicalFunction nes-physical-operators TdistanceTintIntPhysicalFunction.cpp) add_plugin(TdistanceTnumberTnumber PhysicalFunction nes-physical-operators TdistanceTnumberTnumberPhysicalFunction.cpp) add_plugin(TemporalRound PhysicalFunction nes-physical-operators TemporalRoundPhysicalFunction.cpp) +add_plugin(TintScaleValue PhysicalFunction nes-physical-operators TintScaleValuePhysicalFunction.cpp) +add_plugin(TintShiftScaleValue PhysicalFunction nes-physical-operators TintShiftScaleValuePhysicalFunction.cpp) +add_plugin(TintShiftValue PhysicalFunction nes-physical-operators TintShiftValuePhysicalFunction.cpp) add_plugin(DivTintInt PhysicalFunction nes-physical-operators DivTintIntPhysicalFunction.cpp) add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) add_plugin(MulTintInt PhysicalFunction nes-physical-operators MulTintIntPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/TdistanceTintIntPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TdistanceTintIntPhysicalFunction.cpp new file mode 100644 index 0000000000..fc43b94327 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TdistanceTintIntPhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TdistanceTintIntPhysicalFunction::TdistanceTintIntPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction dFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(dFunction)); +} + +VarVal TdistanceTintIntPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto d = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double d_val) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tdistance_tint_int(temp, static_cast(d_val)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, d); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTdistanceTintIntPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TdistanceTintIntPhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TdistanceTintIntPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TintScaleValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TintScaleValuePhysicalFunction.cpp new file mode 100644 index 0000000000..aebbb9ed6b --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TintScaleValuePhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TintScaleValuePhysicalFunction::TintScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction widthFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(widthFunction)); +} + +VarVal TintScaleValuePhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto width = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double width_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tint_scale_value(temp, static_cast(width_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, width); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTintScaleValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TintScaleValuePhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TintScaleValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TintShiftScaleValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TintShiftScaleValuePhysicalFunction.cpp new file mode 100644 index 0000000000..ff1780d328 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TintShiftScaleValuePhysicalFunction.cpp @@ -0,0 +1,95 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TintShiftScaleValuePhysicalFunction::TintShiftScaleValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction, + PhysicalFunction widthFunction) +{ + parameterFunctions.reserve(4); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(shiftFunction)); + parameterFunctions.push_back(std::move(widthFunction)); +} + +VarVal TintShiftScaleValuePhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto shift = parameterValues[2].cast>(); + auto width = parameterValues[3].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double shift_d, double width_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tint_shift_scale_value(temp, static_cast(shift_d), static_cast(width_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, shift, width); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTintShiftScaleValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 4, + "TintShiftScaleValuePhysicalFunction requires 4 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + auto arg3 = std::move(arguments.childFunctions[3]); + return TintShiftScaleValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2), std::move(arg3)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TintShiftValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TintShiftValuePhysicalFunction.cpp new file mode 100644 index 0000000000..608e63b0f7 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TintShiftValuePhysicalFunction.cpp @@ -0,0 +1,91 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TintShiftValuePhysicalFunction::TintShiftValuePhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction, + PhysicalFunction shiftFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); + parameterFunctions.push_back(std::move(shiftFunction)); +} + +VarVal TintShiftValuePhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + auto shift = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts, double shift_d) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tint_shift_value(temp, static_cast(shift_d)); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts, shift); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTintShiftValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TintShiftValuePhysicalFunction requires 3 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + auto arg2 = std::move(arguments.childFunctions[2]); + return TintShiftValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index f41484aa70..4afbde6abd 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TINT_INT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TINT_SCALE_VALUE | TINT_SHIFT_SCALE_VALUE | TINT_SHIFT_VALUE | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -501,6 +501,7 @@ SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; SUB_TINT_INT: 'SUB_TINT_INT' | 'sub_tint_int'; SUB_TNUMBER_TNUMBER: 'SUB_TNUMBER_TNUMBER' | 'sub_tnumber_tnumber'; TDISTANCE_TFLOAT_FLOAT: 'TDISTANCE_TFLOAT_FLOAT' | 'tdistance_tfloat_float'; +TDISTANCE_TINT_INT: 'TDISTANCE_TINT_INT' | 'tdistance_tint_int'; TDISTANCE_TNUMBER_TNUMBER: 'TDISTANCE_TNUMBER_TNUMBER' | 'tdistance_tnumber_tnumber'; TEMPORAL_ROUND: 'TEMPORAL_ROUND' | 'temporal_round'; TFLOAT_CEIL: 'TFLOAT_CEIL' | 'tfloat_ceil'; @@ -513,6 +514,9 @@ TFLOAT_SHIFT_SCALE_VALUE: 'TFLOAT_SHIFT_SCALE_VALUE' | 'tfloat_shift_scale_value TFLOAT_SHIFT_VALUE: 'TFLOAT_SHIFT_VALUE' | 'tfloat_shift_value'; TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; +TINT_SCALE_VALUE: 'TINT_SCALE_VALUE' | 'tint_scale_value'; +TINT_SHIFT_SCALE_VALUE: 'TINT_SHIFT_SCALE_VALUE' | 'tint_shift_scale_value'; +TINT_SHIFT_VALUE: 'TINT_SHIFT_VALUE' | 'tint_shift_value'; TNUMBER_ABS: 'TNUMBER_ABS' | 'tnumber_abs'; WATERMARK: 'WATERMARK' | 'watermark'; OFFSET: 'OFFSET' | 'offset'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 0ed1f77265..cc8764f9be 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1903,6 +1907,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TDISTANCE_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: TDISTANCE_TINT_INT */ + case AntlrSQLLexer::TDISTANCE_TINT_INT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TDISTANCE_TINT_INT requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TdistanceTintIntLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TDISTANCE_TINT_INT */ case AntlrSQLLexer::TDISTANCE_TNUMBER_TNUMBER: { @@ -1961,6 +1994,94 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TEMPORAL_ROUND */ + /* BEGIN CODEGEN PARSER GLUE: TINT_SCALE_VALUE */ + case AntlrSQLLexer::TINT_SCALE_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TINT_SCALE_VALUE requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TintScaleValueLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TINT_SCALE_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TINT_SHIFT_SCALE_VALUE */ + case AntlrSQLLexer::TINT_SHIFT_SCALE_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 4) + throw InvalidQuerySyntax("TINT_SHIFT_SCALE_VALUE requires exactly 4 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a3 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TintShiftScaleValueLogicalFunction(a0, a1, a2, a3)); + } + break; + /* END CODEGEN PARSER GLUE: TINT_SHIFT_SCALE_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TINT_SHIFT_VALUE */ + case AntlrSQLLexer::TINT_SHIFT_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TINT_SHIFT_VALUE requires exactly 3 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a2 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TintShiftValueLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TINT_SHIFT_VALUE */ default: /// Check if the function is a constructor for a datatype From 9be67595e06abffd285bc027f2af0ebb7deeaf41 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:12:05 +0200 Subject: [PATCH 11/12] feat(meos): add TFLOAT_TO_TINT and TINT_TO_TFLOAT type-conversion NES operators (W53) --- .../Meos/TfloatToTintLogicalFunction.hpp | 53 +++++++++ .../Meos/TintToTfloatLogicalFunction.hpp | 53 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 2 + .../Meos/TfloatToTintLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TintToTfloatLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatToTintPhysicalFunction.hpp | 42 ++++++++ .../Meos/TintToTfloatPhysicalFunction.hpp | 42 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 2 + .../Meos/TfloatToTintPhysicalFunction.cpp | 87 +++++++++++++++ .../Meos/TintToTfloatPhysicalFunction.cpp | 88 +++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 4 +- .../src/AntlrSQLQueryPlanCreator.cpp | 58 ++++++++++ 12 files changed, 634 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatToTintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TintToTfloatLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatToTintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TintToTfloatLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatToTintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TintToTfloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatToTintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TintToTfloatPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TfloatToTintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatToTintLogicalFunction.hpp new file mode 100644 index 0000000000..0d47f35168 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatToTintLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_to_tint: converts a single-instant tfloat to tint, returns FLOAT64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_to_tint`. Takes (value:FLOAT64, ts:UINT64), constructs a single-instant + * temporal float, truncates to integer, and returns FLOAT64. + */ +class TfloatToTintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatToTint"; + + TfloatToTintLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TintToTfloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TintToTfloatLogicalFunction.hpp new file mode 100644 index 0000000000..6de528f985 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TintToTfloatLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tint_to_tfloat: converts a single-instant tint to tfloat, returns FLOAT64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tint_to_tfloat`. Takes (value:FLOAT64, ts:UINT64), constructs a single-instant + * temporal integer, promotes to float, and returns FLOAT64. + */ +class TintToTfloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TintToTfloat"; + + TintToTfloatLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 49cd3f9231..4657c2f4fb 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -47,4 +47,6 @@ add_plugin(TfloatShiftScaleValue LogicalFunction nes-logical-operators TfloatShi add_plugin(TfloatShiftValue LogicalFunction nes-logical-operators TfloatShiftValueLogicalFunction.cpp) add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) add_plugin(TfloatTan LogicalFunction nes-logical-operators TfloatTanLogicalFunction.cpp) +add_plugin(TfloatToTint LogicalFunction nes-logical-operators TfloatToTintLogicalFunction.cpp) +add_plugin(TintToTfloat LogicalFunction nes-logical-operators TintToTfloatLogicalFunction.cpp) add_plugin(TnumberAbs LogicalFunction nes-logical-operators TnumberAbsLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TfloatToTintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatToTintLogicalFunction.cpp new file mode 100644 index 0000000000..63bf97d316 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatToTintLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatToTintLogicalFunction::TfloatToTintLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatToTintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatToTintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatToTintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatToTintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatToTintLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatToTintLogicalFunction::getType() const { return NAME; } + +bool TfloatToTintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatToTintLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatToTintLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatToTintLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatToTintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatToTintLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatToTintLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TintToTfloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TintToTfloatLogicalFunction.cpp new file mode 100644 index 0000000000..08c9e80ad4 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TintToTfloatLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TintToTfloatLogicalFunction::TintToTfloatLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TintToTfloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TintToTfloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TintToTfloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TintToTfloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TintToTfloatLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TintToTfloatLogicalFunction::getType() const { return NAME; } + +bool TintToTfloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TintToTfloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TintToTfloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TintToTfloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTintToTfloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TintToTfloatLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TintToTfloatLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatToTintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatToTintPhysicalFunction.hpp new file mode 100644 index 0000000000..48c2bd2f92 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatToTintPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_to_tint`. + * + * Per-event tfloat_to_tint: single-instant tfloat converted to tint, result extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatToTintPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatToTintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TintToTfloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TintToTfloatPhysicalFunction.hpp new file mode 100644 index 0000000000..c338179d9b --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TintToTfloatPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tint_to_tfloat`. + * + * Per-event tint_to_tfloat: single-instant tint promoted to tfloat, result extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TintToTfloatPhysicalFunction : public PhysicalFunctionConcept { +public: + TintToTfloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index 5138cf9b1d..68c2b6a81c 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -46,5 +46,7 @@ add_plugin(TfloatShiftScaleValue PhysicalFunction nes-physical-operators TfloatS add_plugin(TfloatShiftValue PhysicalFunction nes-physical-operators TfloatShiftValuePhysicalFunction.cpp) add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) add_plugin(TfloatTan PhysicalFunction nes-physical-operators TfloatTanPhysicalFunction.cpp) +add_plugin(TfloatToTint PhysicalFunction nes-physical-operators TfloatToTintPhysicalFunction.cpp) +add_plugin(TintToTfloat PhysicalFunction nes-physical-operators TintToTfloatPhysicalFunction.cpp) add_plugin(TnumberAbs PhysicalFunction nes-physical-operators TnumberAbsPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/TfloatToTintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatToTintPhysicalFunction.cpp new file mode 100644 index 0000000000..1c2f2cca6d --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatToTintPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatToTintPhysicalFunction::TfloatToTintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatToTintPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_to_tint(temp); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatToTintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatToTintPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatToTintPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TintToTfloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TintToTfloatPhysicalFunction.cpp new file mode 100644 index 0000000000..23eb9eb5dc --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TintToTfloatPhysicalFunction.cpp @@ -0,0 +1,88 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TintToTfloatPhysicalFunction::TintToTfloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TintToTfloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), + MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tint_to_tfloat(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTintToTfloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TintToTfloatPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TintToTfloatPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 4afbde6abd..904df4a954 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TINT_INT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TINT_SCALE_VALUE | TINT_SHIFT_SCALE_VALUE | TINT_SHIFT_VALUE | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TINT_INT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TFLOAT_TO_TINT | TINT_SCALE_VALUE | TINT_SHIFT_SCALE_VALUE | TINT_SHIFT_VALUE | TINT_TO_TFLOAT | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -514,9 +514,11 @@ TFLOAT_SHIFT_SCALE_VALUE: 'TFLOAT_SHIFT_SCALE_VALUE' | 'tfloat_shift_scale_value TFLOAT_SHIFT_VALUE: 'TFLOAT_SHIFT_VALUE' | 'tfloat_shift_value'; TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; +TFLOAT_TO_TINT: 'TFLOAT_TO_TINT' | 'tfloat_to_tint'; TINT_SCALE_VALUE: 'TINT_SCALE_VALUE' | 'tint_scale_value'; TINT_SHIFT_SCALE_VALUE: 'TINT_SHIFT_SCALE_VALUE' | 'tint_shift_scale_value'; TINT_SHIFT_VALUE: 'TINT_SHIFT_VALUE' | 'tint_shift_value'; +TINT_TO_TFLOAT: 'TINT_TO_TFLOAT' | 'tint_to_tfloat'; TNUMBER_ABS: 'TNUMBER_ABS' | 'tnumber_abs'; WATERMARK: 'WATERMARK' | 'watermark'; OFFSET: 'OFFSET' | 'offset'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index cc8764f9be..ffecad8e62 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -95,9 +95,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -1301,6 +1303,34 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_TAN */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_TO_TINT */ + case AntlrSQLLexer::TFLOAT_TO_TINT: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_TO_TINT requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatToTintLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_TO_TINT */ /* BEGIN CODEGEN PARSER GLUE: TFLOAT_CEIL */ case AntlrSQLLexer::TFLOAT_CEIL: { @@ -2082,6 +2112,34 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TINT_SHIFT_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TINT_TO_TFLOAT */ + case AntlrSQLLexer::TINT_TO_TFLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TINT_TO_TFLOAT requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TintToTfloatLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TINT_TO_TFLOAT */ default: /// Check if the function is a constructor for a datatype From e53bbc132459a4902fc6b1550da98ce2787188a8 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:18:42 +0200 Subject: [PATCH 12/12] feat(meos): add tbigint type-conversion NES operators TBIGINT_TO_TINT, TBIGINT_TO_TFLOAT, TINT_TO_TBIGINT, TFLOAT_TO_TBIGINT (W54) --- .../Meos/TbigintToTfloatLogicalFunction.hpp | 53 ++++++++ .../Meos/TbigintToTintLogicalFunction.hpp | 53 ++++++++ .../Meos/TfloatToTbigintLogicalFunction.hpp | 53 ++++++++ .../Meos/TintToTbigintLogicalFunction.hpp | 53 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/TbigintToTfloatLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TbigintToTintLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TfloatToTbigintLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TintToTbigintLogicalFunction.cpp | 102 +++++++++++++++ .../Meos/TbigintToTfloatPhysicalFunction.hpp | 42 +++++++ .../Meos/TbigintToTintPhysicalFunction.hpp | 42 +++++++ .../Meos/TfloatToTbigintPhysicalFunction.hpp | 42 +++++++ .../Meos/TintToTbigintPhysicalFunction.hpp | 42 +++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/TbigintToTfloatPhysicalFunction.cpp | 87 +++++++++++++ .../Meos/TbigintToTintPhysicalFunction.cpp | 87 +++++++++++++ .../Meos/TfloatToTbigintPhysicalFunction.cpp | 87 +++++++++++++ .../Meos/TintToTbigintPhysicalFunction.cpp | 87 +++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 116 ++++++++++++++++++ 20 files changed, 1265 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TbigintToTfloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TbigintToTintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatToTbigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TintToTbigintLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TbigintToTfloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TbigintToTintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatToTbigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TintToTbigintLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TbigintToTfloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TbigintToTintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatToTbigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TintToTbigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TbigintToTfloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TbigintToTintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatToTbigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TintToTbigintPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TbigintToTfloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TbigintToTfloatLogicalFunction.hpp new file mode 100644 index 0000000000..aafccec021 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TbigintToTfloatLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tbigint_to_tfloat: converts a single-instant tbigint to tfloat, returns FLOAT64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tbigint_to_tfloat`. Takes (value:FLOAT64, ts:UINT64), constructs a single-instant + * temporal bigint, widens to float, and returns FLOAT64. + */ +class TbigintToTfloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TbigintToTfloat"; + + TbigintToTfloatLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TbigintToTintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TbigintToTintLogicalFunction.hpp new file mode 100644 index 0000000000..78e9cbb7d3 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TbigintToTintLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tbigint_to_tint: converts a single-instant tbigint to tint, returns FLOAT64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tbigint_to_tint`. Takes (value:FLOAT64, ts:UINT64), constructs a single-instant + * temporal bigint, narrows to integer, and returns FLOAT64. + */ +class TbigintToTintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TbigintToTint"; + + TbigintToTintLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TfloatToTbigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatToTbigintLogicalFunction.hpp new file mode 100644 index 0000000000..67a04b12b5 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatToTbigintLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tfloat_to_tbigint: converts a single-instant tfloat to tbigint, returns FLOAT64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_to_tbigint`. Takes (value:FLOAT64, ts:UINT64), constructs a single-instant + * temporal float, truncates to bigint, and returns FLOAT64. + */ +class TfloatToTbigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatToTbigint"; + + TfloatToTbigintLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/include/Functions/Meos/TintToTbigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TintToTbigintLogicalFunction.hpp new file mode 100644 index 0000000000..f9460e7edd --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TintToTbigintLogicalFunction.hpp @@ -0,0 +1,53 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Per-event tint_to_tbigint: converts a single-instant tint to tbigint, returns FLOAT64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tint_to_tbigint`. Takes (value:FLOAT64, ts:UINT64), constructs a single-instant + * temporal integer, widens to bigint, and returns FLOAT64. + */ +class TintToTbigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TintToTbigint"; + + TintToTbigintLogicalFunction(LogicalFunction value, + LogicalFunction ts); + + DataType getDataType() const override; + LogicalFunction withDataType(const DataType& dataType) const override; + std::vector getChildren() const override; + LogicalFunction withChildren(const std::vector& children) const override; + std::string_view getType() const override; + bool operator==(const LogicalFunctionConcept& rhs) const override; + std::string explain(ExplainVerbosity verbosity) const override; + LogicalFunction withInferredDataType(const Schema& schema) const override; + SerializableFunction serialize() const override; + +private: + DataType dataType; + std::vector parameters; +}; + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt index 4657c2f4fb..50e5392a95 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -47,6 +47,10 @@ add_plugin(TfloatShiftScaleValue LogicalFunction nes-logical-operators TfloatShi add_plugin(TfloatShiftValue LogicalFunction nes-logical-operators TfloatShiftValueLogicalFunction.cpp) add_plugin(TfloatSin LogicalFunction nes-logical-operators TfloatSinLogicalFunction.cpp) add_plugin(TfloatTan LogicalFunction nes-logical-operators TfloatTanLogicalFunction.cpp) +add_plugin(TbigintToTfloat LogicalFunction nes-logical-operators TbigintToTfloatLogicalFunction.cpp) +add_plugin(TbigintToTint LogicalFunction nes-logical-operators TbigintToTintLogicalFunction.cpp) +add_plugin(TfloatToTbigint LogicalFunction nes-logical-operators TfloatToTbigintLogicalFunction.cpp) add_plugin(TfloatToTint LogicalFunction nes-logical-operators TfloatToTintLogicalFunction.cpp) +add_plugin(TintToTbigint LogicalFunction nes-logical-operators TintToTbigintLogicalFunction.cpp) add_plugin(TintToTfloat LogicalFunction nes-logical-operators TintToTfloatLogicalFunction.cpp) add_plugin(TnumberAbs LogicalFunction nes-logical-operators TnumberAbsLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TbigintToTfloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TbigintToTfloatLogicalFunction.cpp new file mode 100644 index 0000000000..65b2a6cefd --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TbigintToTfloatLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TbigintToTfloatLogicalFunction::TbigintToTfloatLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TbigintToTfloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TbigintToTfloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TbigintToTfloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TbigintToTfloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TbigintToTfloatLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TbigintToTfloatLogicalFunction::getType() const { return NAME; } + +bool TbigintToTfloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TbigintToTfloatLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TbigintToTfloatLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TbigintToTfloatLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTbigintToTfloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TbigintToTfloatLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TbigintToTfloatLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TbigintToTintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TbigintToTintLogicalFunction.cpp new file mode 100644 index 0000000000..312df7d30a --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TbigintToTintLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TbigintToTintLogicalFunction::TbigintToTintLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TbigintToTintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TbigintToTintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TbigintToTintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TbigintToTintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TbigintToTintLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TbigintToTintLogicalFunction::getType() const { return NAME; } + +bool TbigintToTintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TbigintToTintLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TbigintToTintLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TbigintToTintLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTbigintToTintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TbigintToTintLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TbigintToTintLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatToTbigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatToTbigintLogicalFunction.cpp new file mode 100644 index 0000000000..b86add8d10 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatToTbigintLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TfloatToTbigintLogicalFunction::TfloatToTbigintLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TfloatToTbigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatToTbigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatToTbigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatToTbigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatToTbigintLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatToTbigintLogicalFunction::getType() const { return NAME; } + +bool TfloatToTbigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatToTbigintLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TfloatToTbigintLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TfloatToTbigintLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTfloatToTbigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatToTbigintLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatToTbigintLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TintToTbigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TintToTbigintLogicalFunction.cpp new file mode 100644 index 0000000000..681eb6857d --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TintToTbigintLogicalFunction.cpp @@ -0,0 +1,102 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NES +{ + +TintToTbigintLogicalFunction::TintToTbigintLogicalFunction(LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(2); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType TintToTbigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TintToTbigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TintToTbigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TintToTbigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TintToTbigintLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TintToTbigintLogicalFunction::getType() const { return NAME; } + +bool TintToTbigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TintToTbigintLogicalFunction::explain(ExplainVerbosity verbosity) const +{ + std::string args; + for (size_t index = 0; index < parameters.size(); ++index) { + if (index > 0) args += ", "; + args += parameters[index].explain(verbosity); + } + return fmt::format("{}({})", NAME, args); +} + +LogicalFunction TintToTbigintLogicalFunction::withInferredDataType(const Schema& schema) const +{ + std::vector newChildren; + newChildren.reserve(parameters.size()); + for (const auto& child : parameters) + newChildren.emplace_back(child.withInferredDataType(schema)); + return withChildren(newChildren); +} + +SerializableFunction TintToTbigintLogicalFunction::serialize() const +{ + SerializableFunction proto; + proto.set_function_type(std::string(NAME)); + DataTypeSerializationUtil::serializeDataType(dataType, proto.mutable_data_type()); + for (const auto& child : parameters) + proto.add_children()->CopyFrom(child.serialize()); + return proto; +} + +LogicalFunctionRegistryReturnType LogicalFunctionGeneratedRegistrar::RegisterTintToTbigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TintToTbigintLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TintToTbigintLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TbigintToTfloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TbigintToTfloatPhysicalFunction.hpp new file mode 100644 index 0000000000..a59b288ff5 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TbigintToTfloatPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tbigint_to_tfloat`. + * + * Per-event tbigint_to_tfloat: single-instant tbigint converted to tfloat, result extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TbigintToTfloatPhysicalFunction : public PhysicalFunctionConcept { +public: + TbigintToTfloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TbigintToTintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TbigintToTintPhysicalFunction.hpp new file mode 100644 index 0000000000..a122dcf560 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TbigintToTintPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tbigint_to_tint`. + * + * Per-event tbigint_to_tint: single-instant tbigint converted to tint, result extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TbigintToTintPhysicalFunction : public PhysicalFunctionConcept { +public: + TbigintToTintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatToTbigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatToTbigintPhysicalFunction.hpp new file mode 100644 index 0000000000..0a6d8397fb --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatToTbigintPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tfloat_to_tbigint`. + * + * Per-event tfloat_to_tbigint: single-instant tfloat converted to tbigint, result extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatToTbigintPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatToTbigintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TintToTbigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TintToTbigintPhysicalFunction.hpp new file mode 100644 index 0000000000..0d761ed1a8 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TintToTbigintPhysicalFunction.hpp @@ -0,0 +1,42 @@ +/* + 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 + + https://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. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace NES { + +/** + * @brief Physical operator for `tint_to_tbigint`. + * + * Per-event tint_to_tbigint: single-instant tint converted to tbigint, result extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TintToTbigintPhysicalFunction : public PhysicalFunctionConcept { +public: + TintToTbigintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction); + + VarVal execute(const Record& record, ArenaRef& arena) const override; + +private: + std::vector parameterFunctions; +}; + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt index 68c2b6a81c..3b10b0af05 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -46,7 +46,11 @@ add_plugin(TfloatShiftScaleValue PhysicalFunction nes-physical-operators TfloatS add_plugin(TfloatShiftValue PhysicalFunction nes-physical-operators TfloatShiftValuePhysicalFunction.cpp) add_plugin(TfloatSin PhysicalFunction nes-physical-operators TfloatSinPhysicalFunction.cpp) add_plugin(TfloatTan PhysicalFunction nes-physical-operators TfloatTanPhysicalFunction.cpp) +add_plugin(TbigintToTfloat PhysicalFunction nes-physical-operators TbigintToTfloatPhysicalFunction.cpp) +add_plugin(TbigintToTint PhysicalFunction nes-physical-operators TbigintToTintPhysicalFunction.cpp) +add_plugin(TfloatToTbigint PhysicalFunction nes-physical-operators TfloatToTbigintPhysicalFunction.cpp) add_plugin(TfloatToTint PhysicalFunction nes-physical-operators TfloatToTintPhysicalFunction.cpp) +add_plugin(TintToTbigint PhysicalFunction nes-physical-operators TintToTbigintPhysicalFunction.cpp) add_plugin(TintToTfloat PhysicalFunction nes-physical-operators TintToTfloatPhysicalFunction.cpp) add_plugin(TnumberAbs PhysicalFunction nes-physical-operators TnumberAbsPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/TbigintToTfloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TbigintToTfloatPhysicalFunction.cpp new file mode 100644 index 0000000000..a8ba3a08b4 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TbigintToTfloatPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TbigintToTfloatPhysicalFunction::TbigintToTfloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TbigintToTfloatPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tbigint_to_tfloat(temp); + free(temp); + if (!res) return 0.0; + double r = tfloat_start_value(res); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTbigintToTfloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TbigintToTfloatPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TbigintToTfloatPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TbigintToTintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TbigintToTintPhysicalFunction.cpp new file mode 100644 index 0000000000..32a231a74a --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TbigintToTintPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TbigintToTintPhysicalFunction::TbigintToTintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TbigintToTintPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tbigint_to_tint(temp); + free(temp); + if (!res) return 0.0; + double r = static_cast(tint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTbigintToTintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TbigintToTintPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TbigintToTintPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatToTbigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatToTbigintPhysicalFunction.cpp new file mode 100644 index 0000000000..9549684d2b --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatToTbigintPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TfloatToTbigintPhysicalFunction::TfloatToTbigintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatToTbigintPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", value, MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tfloat_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tfloat_to_tbigint(temp); + free(temp); + if (!res) return 0.0; + double r = static_cast(tbigint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTfloatToTbigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatToTbigintPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatToTbigintPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TintToTbigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TintToTbigintPhysicalFunction.cpp new file mode 100644 index 0000000000..36a685a163 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TintToTbigintPhysicalFunction.cpp @@ -0,0 +1,87 @@ +/* + 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 + + https://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. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +namespace NES { + +TintToTbigintPhysicalFunction::TintToTbigintPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TintToTbigintPhysicalFunction::execute(const Record& record, ArenaRef& arena) const +{ + std::vector parameterValues; + parameterValues.reserve(parameterFunctions.size()); + for (const auto& function : parameterFunctions) + parameterValues.emplace_back(function.execute(record, arena)); + + auto value = parameterValues[0].cast>(); + auto ts = parameterValues[1].cast>(); + + const auto result = nautilus::invoke( + +[](double value, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tint_to_tbigint(temp); + free(temp); + if (!res) return 0.0; + double r = static_cast(tbigint_start_value(res)); + free(res); + return r; + } catch (const std::exception&) { return 0.0; } + }, + value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTintToTbigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TintToTbigintPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TintToTbigintPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index 904df4a954..3c0413fb45 100644 --- a/nes-sql-parser/AntlrSQL.g4 +++ b/nes-sql-parser/AntlrSQL.g4 @@ -295,7 +295,7 @@ timeUnit: MS timestampParameter: name=identifier; -functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TINT_INT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TFLOAT_TO_TINT | TINT_SCALE_VALUE | TINT_SHIFT_SCALE_VALUE | TINT_SHIFT_VALUE | TINT_TO_TFLOAT | TNUMBER_ABS; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | EDWITHIN_TGEO_GEO | TGEO_AT_STBOX | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TFLOAT_FLOAT | SUB_TINT_INT | SUB_TNUMBER_TNUMBER | TDISTANCE_TFLOAT_FLOAT | TDISTANCE_TINT_INT | TDISTANCE_TNUMBER_TNUMBER | TEMPORAL_ROUND | TFLOAT_CEIL | TFLOAT_COS | TFLOAT_DEGREES | TFLOAT_FLOOR | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TBIGINT_TO_TFLOAT | TBIGINT_TO_TINT | TFLOAT_SHIFT_VALUE | TFLOAT_SIN | TFLOAT_TAN | TFLOAT_TO_TBIGINT | TFLOAT_TO_TINT | TINT_SCALE_VALUE | TINT_SHIFT_SCALE_VALUE | TINT_SHIFT_VALUE | TINT_TO_TBIGINT | TINT_TO_TFLOAT | TNUMBER_ABS; sinkClause: INTO sink (',' sink)*; @@ -500,6 +500,8 @@ MUL_TNUMBER_TNUMBER: 'MUL_TNUMBER_TNUMBER' | 'mul_tnumber_tnumber'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; SUB_TINT_INT: 'SUB_TINT_INT' | 'sub_tint_int'; SUB_TNUMBER_TNUMBER: 'SUB_TNUMBER_TNUMBER' | 'sub_tnumber_tnumber'; +TBIGINT_TO_TFLOAT: 'TBIGINT_TO_TFLOAT' | 'tbigint_to_tfloat'; +TBIGINT_TO_TINT: 'TBIGINT_TO_TINT' | 'tbigint_to_tint'; TDISTANCE_TFLOAT_FLOAT: 'TDISTANCE_TFLOAT_FLOAT' | 'tdistance_tfloat_float'; TDISTANCE_TINT_INT: 'TDISTANCE_TINT_INT' | 'tdistance_tint_int'; TDISTANCE_TNUMBER_TNUMBER: 'TDISTANCE_TNUMBER_TNUMBER' | 'tdistance_tnumber_tnumber'; @@ -514,10 +516,12 @@ TFLOAT_SHIFT_SCALE_VALUE: 'TFLOAT_SHIFT_SCALE_VALUE' | 'tfloat_shift_scale_value TFLOAT_SHIFT_VALUE: 'TFLOAT_SHIFT_VALUE' | 'tfloat_shift_value'; TFLOAT_SIN: 'TFLOAT_SIN' | 'tfloat_sin'; TFLOAT_TAN: 'TFLOAT_TAN' | 'tfloat_tan'; +TFLOAT_TO_TBIGINT: 'TFLOAT_TO_TBIGINT' | 'tfloat_to_tbigint'; TFLOAT_TO_TINT: 'TFLOAT_TO_TINT' | 'tfloat_to_tint'; TINT_SCALE_VALUE: 'TINT_SCALE_VALUE' | 'tint_scale_value'; TINT_SHIFT_SCALE_VALUE: 'TINT_SHIFT_SCALE_VALUE' | 'tint_shift_scale_value'; TINT_SHIFT_VALUE: 'TINT_SHIFT_VALUE' | 'tint_shift_value'; +TINT_TO_TBIGINT: 'TINT_TO_TBIGINT' | 'tint_to_tbigint'; TINT_TO_TFLOAT: 'TINT_TO_TFLOAT' | 'tint_to_tfloat'; TNUMBER_ABS: 'TNUMBER_ABS' | 'tnumber_abs'; WATERMARK: 'WATERMARK' | 'watermark'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index ffecad8e62..427782a1ea 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -81,6 +81,8 @@ #include #include #include +#include +#include #include #include #include @@ -95,10 +97,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -1303,6 +1307,34 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_TAN */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_TO_TBIGINT */ + case AntlrSQLLexer::TFLOAT_TO_TBIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_TO_TBIGINT requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TfloatToTbigintLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_TO_TBIGINT */ /* BEGIN CODEGEN PARSER GLUE: TFLOAT_TO_TINT */ case AntlrSQLLexer::TFLOAT_TO_TINT: { @@ -1908,6 +1940,62 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TNUMBER_TNUMBER */ + /* BEGIN CODEGEN PARSER GLUE: TBIGINT_TO_TFLOAT */ + case AntlrSQLLexer::TBIGINT_TO_TFLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TBIGINT_TO_TFLOAT requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TbigintToTfloatLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TBIGINT_TO_TFLOAT */ + /* BEGIN CODEGEN PARSER GLUE: TBIGINT_TO_TINT */ + case AntlrSQLLexer::TBIGINT_TO_TINT: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TBIGINT_TO_TINT requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TbigintToTintLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TBIGINT_TO_TINT */ case AntlrSQLLexer::TDISTANCE_TFLOAT_FLOAT: { @@ -2112,6 +2200,34 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TINT_SHIFT_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TINT_TO_TBIGINT */ + case AntlrSQLLexer::TINT_TO_TBIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TINT_TO_TBIGINT requires exactly 2 arguments, but got {}", argCount); + + while (!helpers.top().constantBuilder.empty()) + { + auto constantValue = std::move(helpers.top().constantBuilder.back()); + helpers.top().constantBuilder.pop_back(); + DataType dataType; + char* endPtr = nullptr; + std::strtod(constantValue.c_str(), &endPtr); + if (endPtr != nullptr && *endPtr == '\0') + dataType = DataTypeProvider::provideDataType(DataType::Type::FLOAT64); + else + dataType = DataTypeProvider::provideDataType(DataType::Type::VARSIZED); + helpers.top().functionBuilder.emplace_back(ConstantValueLogicalFunction(dataType, std::move(constantValue))); + } + + auto a1 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + auto a0 = helpers.top().functionBuilder.back(); helpers.top().functionBuilder.pop_back(); + + helpers.top().functionBuilder.emplace_back(TintToTbigintLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TINT_TO_TBIGINT */ /* BEGIN CODEGEN PARSER GLUE: TINT_TO_TFLOAT */ case AntlrSQLLexer::TINT_TO_TFLOAT: {