From 6b54911a6c9c8637873b4839f69a3817e53cda3c Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Thu, 11 Jun 2026 20:32:32 +0200 Subject: [PATCH 01/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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: { From 677ea809cd9deeb98df40015f74705a545669853 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:24:39 +0200 Subject: [PATCH 13/20] feat(meos): add ADD/SUB/MUL/DIV_TBIGINT_BIGINT NES operators (W55) --- .../Meos/AddTbigintBigintLogicalFunction.hpp | 54 ++++++++ .../Meos/DivTbigintBigintLogicalFunction.hpp | 54 ++++++++ .../Meos/MulTbigintBigintLogicalFunction.hpp | 54 ++++++++ .../Meos/SubTbigintBigintLogicalFunction.hpp | 54 ++++++++ .../Meos/AddTbigintBigintLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTbigintBigintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulTbigintBigintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubTbigintBigintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/AddTbigintBigintPhysicalFunction.hpp | 43 +++++++ .../Meos/DivTbigintBigintPhysicalFunction.hpp | 43 +++++++ .../Meos/MulTbigintBigintPhysicalFunction.hpp | 43 +++++++ .../Meos/SubTbigintBigintPhysicalFunction.hpp | 43 +++++++ .../Meos/AddTbigintBigintPhysicalFunction.cpp | 92 ++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivTbigintBigintPhysicalFunction.cpp | 92 ++++++++++++++ .../Meos/MulTbigintBigintPhysicalFunction.cpp | 92 ++++++++++++++ .../Meos/SubTbigintBigintPhysicalFunction.cpp | 92 ++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 120 ++++++++++++++++++ 20 files changed, 1309 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/AddTbigintBigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivTbigintBigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulTbigintBigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubTbigintBigintLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddTbigintBigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivTbigintBigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulTbigintBigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubTbigintBigintLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddTbigintBigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivTbigintBigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulTbigintBigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubTbigintBigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddTbigintBigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivTbigintBigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulTbigintBigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubTbigintBigintPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddTbigintBigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddTbigintBigintLogicalFunction.hpp new file mode 100644 index 0000000000..c97f49cb16 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddTbigintBigintLogicalFunction.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_tbigint_bigint: adds a constant int64 to a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_tbigint_bigint`. Takes (value:FLOAT64, ts:UINT64, addend:FLOAT64→int64), + * constructs a single-instant temporal, applies the addition, and returns FLOAT64. + */ +class AddTbigintBigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddTbigintBigint"; + + AddTbigintBigintLogicalFunction(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/DivTbigintBigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivTbigintBigintLogicalFunction.hpp new file mode 100644 index 0000000000..48d916f76d --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivTbigintBigintLogicalFunction.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_tbigint_bigint: divides a single-instant tbigint value by a constant int64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_tbigint_bigint`. Takes (value:FLOAT64, ts:UINT64, divisor:FLOAT64→int64), + * constructs a single-instant temporal, applies the division, and returns FLOAT64. + */ +class DivTbigintBigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivTbigintBigint"; + + DivTbigintBigintLogicalFunction(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/MulTbigintBigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulTbigintBigintLogicalFunction.hpp new file mode 100644 index 0000000000..ff857a8773 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulTbigintBigintLogicalFunction.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_tbigint_bigint: multiplies a single-instant tbigint value by a constant int64. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_tbigint_bigint`. Takes (value:FLOAT64, ts:UINT64, factor:FLOAT64→int64), + * constructs a single-instant temporal, applies the multiplication, and returns FLOAT64. + */ +class MulTbigintBigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulTbigintBigint"; + + MulTbigintBigintLogicalFunction(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/SubTbigintBigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubTbigintBigintLogicalFunction.hpp new file mode 100644 index 0000000000..c1ff3f9a15 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubTbigintBigintLogicalFunction.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_tbigint_bigint: subtracts a constant int64 from a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_tbigint_bigint`. Takes (value:FLOAT64, ts:UINT64, subtrahend:FLOAT64→int64), + * constructs a single-instant temporal, applies the subtraction, and returns FLOAT64. + */ +class SubTbigintBigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubTbigintBigint"; + + SubTbigintBigintLogicalFunction(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/AddTbigintBigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddTbigintBigintLogicalFunction.cpp new file mode 100644 index 0000000000..68d4e06d74 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddTbigintBigintLogicalFunction.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 +{ + +AddTbigintBigintLogicalFunction::AddTbigintBigintLogicalFunction(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 AddTbigintBigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddTbigintBigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddTbigintBigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddTbigintBigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddTbigintBigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddTbigintBigintLogicalFunction::getType() const { return NAME; } + +bool AddTbigintBigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddTbigintBigintLogicalFunction::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 AddTbigintBigintLogicalFunction::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 AddTbigintBigintLogicalFunction::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::RegisterAddTbigintBigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddTbigintBigintLogicalFunction 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 AddTbigintBigintLogicalFunction(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 50e5392a95..58a9c60a18 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -25,6 +25,7 @@ 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(AddTbigintBigint LogicalFunction nes-logical-operators AddTbigintBigintLogicalFunction.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) @@ -34,10 +35,13 @@ add_plugin(TemporalRound LogicalFunction nes-logical-operators TemporalRoundLogi 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(DivTbigintBigint LogicalFunction nes-logical-operators DivTbigintBigintLogicalFunction.cpp) add_plugin(DivTintInt LogicalFunction nes-logical-operators DivTintIntLogicalFunction.cpp) add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) +add_plugin(MulTbigintBigint LogicalFunction nes-logical-operators MulTbigintBigintLogicalFunction.cpp) add_plugin(MulTintInt LogicalFunction nes-logical-operators MulTintIntLogicalFunction.cpp) add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnumberLogicalFunction.cpp) +add_plugin(SubTbigintBigint LogicalFunction nes-logical-operators SubTbigintBigintLogicalFunction.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) diff --git a/nes-logical-operators/src/Functions/Meos/DivTbigintBigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivTbigintBigintLogicalFunction.cpp new file mode 100644 index 0000000000..3f200be7c9 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivTbigintBigintLogicalFunction.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 +{ + +DivTbigintBigintLogicalFunction::DivTbigintBigintLogicalFunction(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 DivTbigintBigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivTbigintBigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivTbigintBigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivTbigintBigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivTbigintBigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivTbigintBigintLogicalFunction::getType() const { return NAME; } + +bool DivTbigintBigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivTbigintBigintLogicalFunction::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 DivTbigintBigintLogicalFunction::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 DivTbigintBigintLogicalFunction::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::RegisterDivTbigintBigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivTbigintBigintLogicalFunction 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 DivTbigintBigintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulTbigintBigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulTbigintBigintLogicalFunction.cpp new file mode 100644 index 0000000000..0d1e68e0d1 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulTbigintBigintLogicalFunction.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 +{ + +MulTbigintBigintLogicalFunction::MulTbigintBigintLogicalFunction(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 MulTbigintBigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulTbigintBigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulTbigintBigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulTbigintBigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulTbigintBigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulTbigintBigintLogicalFunction::getType() const { return NAME; } + +bool MulTbigintBigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulTbigintBigintLogicalFunction::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 MulTbigintBigintLogicalFunction::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 MulTbigintBigintLogicalFunction::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::RegisterMulTbigintBigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulTbigintBigintLogicalFunction 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 MulTbigintBigintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubTbigintBigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubTbigintBigintLogicalFunction.cpp new file mode 100644 index 0000000000..ba377c8c8a --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubTbigintBigintLogicalFunction.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 +{ + +SubTbigintBigintLogicalFunction::SubTbigintBigintLogicalFunction(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 SubTbigintBigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubTbigintBigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubTbigintBigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubTbigintBigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubTbigintBigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubTbigintBigintLogicalFunction::getType() const { return NAME; } + +bool SubTbigintBigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubTbigintBigintLogicalFunction::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 SubTbigintBigintLogicalFunction::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 SubTbigintBigintLogicalFunction::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::RegisterSubTbigintBigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubTbigintBigintLogicalFunction 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 SubTbigintBigintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddTbigintBigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddTbigintBigintPhysicalFunction.hpp new file mode 100644 index 0000000000..86f61b764c --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddTbigintBigintPhysicalFunction.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_tbigint_bigint`. + * + * Per-event add_tbigint_bigint: adds a constant int64 to a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddTbigintBigintPhysicalFunction : public PhysicalFunctionConcept { +public: + AddTbigintBigintPhysicalFunction(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/DivTbigintBigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivTbigintBigintPhysicalFunction.hpp new file mode 100644 index 0000000000..aafdd6ad39 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivTbigintBigintPhysicalFunction.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_tbigint_bigint`. + * + * Per-event div_tbigint_bigint: divides a single-instant tbigint value by a constant int64. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivTbigintBigintPhysicalFunction : public PhysicalFunctionConcept { +public: + DivTbigintBigintPhysicalFunction(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/MulTbigintBigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulTbigintBigintPhysicalFunction.hpp new file mode 100644 index 0000000000..3736f42e2d --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulTbigintBigintPhysicalFunction.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_tbigint_bigint`. + * + * Per-event mul_tbigint_bigint: multiplies a single-instant tbigint value by a constant int64. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulTbigintBigintPhysicalFunction : public PhysicalFunctionConcept { +public: + MulTbigintBigintPhysicalFunction(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/SubTbigintBigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubTbigintBigintPhysicalFunction.hpp new file mode 100644 index 0000000000..5e42e74482 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubTbigintBigintPhysicalFunction.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_tbigint_bigint`. + * + * Per-event sub_tbigint_bigint: subtracts a constant int64 from a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubTbigintBigintPhysicalFunction : public PhysicalFunctionConcept { +public: + SubTbigintBigintPhysicalFunction(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/AddTbigintBigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddTbigintBigintPhysicalFunction.cpp new file mode 100644 index 0000000000..0744733c6f --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddTbigintBigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +AddTbigintBigintPhysicalFunction::AddTbigintBigintPhysicalFunction(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 AddTbigintBigintPhysicalFunction::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 = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = add_tbigint_bigint(temp, static_cast(addend_d)); + 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, addend); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddTbigintBigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddTbigintBigintPhysicalFunction 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 AddTbigintBigintPhysicalFunction(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 3b10b0af05..96feed49a1 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -24,6 +24,7 @@ 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(AddTbigintBigint PhysicalFunction nes-physical-operators AddTbigintBigintPhysicalFunction.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) @@ -33,10 +34,13 @@ add_plugin(TemporalRound PhysicalFunction nes-physical-operators TemporalRoundPh 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(DivTbigintBigint PhysicalFunction nes-physical-operators DivTbigintBigintPhysicalFunction.cpp) add_plugin(DivTintInt PhysicalFunction nes-physical-operators DivTintIntPhysicalFunction.cpp) add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) +add_plugin(MulTbigintBigint PhysicalFunction nes-physical-operators MulTbigintBigintPhysicalFunction.cpp) add_plugin(MulTintInt PhysicalFunction nes-physical-operators MulTintIntPhysicalFunction.cpp) add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberTnumberPhysicalFunction.cpp) +add_plugin(SubTbigintBigint PhysicalFunction nes-physical-operators SubTbigintBigintPhysicalFunction.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) diff --git a/nes-physical-operators/src/Functions/Meos/DivTbigintBigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivTbigintBigintPhysicalFunction.cpp new file mode 100644 index 0000000000..381188aedf --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivTbigintBigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +DivTbigintBigintPhysicalFunction::DivTbigintBigintPhysicalFunction(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 DivTbigintBigintPhysicalFunction::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 = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = div_tbigint_bigint(temp, static_cast(divisor_d)); + 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, divisor); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivTbigintBigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivTbigintBigintPhysicalFunction 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 DivTbigintBigintPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulTbigintBigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulTbigintBigintPhysicalFunction.cpp new file mode 100644 index 0000000000..b99b8a6441 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulTbigintBigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +MulTbigintBigintPhysicalFunction::MulTbigintBigintPhysicalFunction(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 MulTbigintBigintPhysicalFunction::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_d) -> 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 = mul_tbigint_bigint(temp, static_cast(factor_d)); + 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, factor); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulTbigintBigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulTbigintBigintPhysicalFunction 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 MulTbigintBigintPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubTbigintBigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubTbigintBigintPhysicalFunction.cpp new file mode 100644 index 0000000000..f625c29498 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubTbigintBigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +SubTbigintBigintPhysicalFunction::SubTbigintBigintPhysicalFunction(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 SubTbigintBigintPhysicalFunction::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 = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = sub_tbigint_bigint(temp, static_cast(subtrahend_d)); + 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, subtrahend); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubTbigintBigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubTbigintBigintPhysicalFunction 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 SubTbigintBigintPhysicalFunction(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 3c0413fb45..390a9bf826 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 | 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; +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_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TBIGINT_BIGINT | 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)*; @@ -488,15 +488,19 @@ 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_TBIGINT_BIGINT: 'ADD_TBIGINT_BIGINT' | 'add_tbigint_bigint'; 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_TBIGINT_BIGINT: 'DIV_TBIGINT_BIGINT' | 'div_tbigint_bigint'; 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_TBIGINT_BIGINT: 'MUL_TBIGINT_BIGINT' | 'mul_tbigint_bigint'; 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_TBIGINT_BIGINT: 'SUB_TBIGINT_BIGINT' | 'sub_tbigint_bigint'; 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'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 427782a1ea..065bc99553 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -69,15 +69,19 @@ #include #include #include +#include #include #include #include +#include #include #include #include +#include #include #include #include +#include #include #include #include @@ -1707,6 +1711,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ADD_TBIGINT_BIGINT */ + case AntlrSQLLexer::ADD_TBIGINT_BIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_TBIGINT_BIGINT 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(AddTbigintBigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_TBIGINT_BIGINT */ case AntlrSQLLexer::ADD_TINT_INT: { @@ -1736,6 +1769,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: ADD_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: DIV_TBIGINT_BIGINT */ + case AntlrSQLLexer::DIV_TBIGINT_BIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_TBIGINT_BIGINT 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(DivTbigintBigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_TBIGINT_BIGINT */ case AntlrSQLLexer::DIV_TINT_INT: { @@ -1765,6 +1827,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: DIV_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: MUL_TBIGINT_BIGINT */ + case AntlrSQLLexer::MUL_TBIGINT_BIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_TBIGINT_BIGINT 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(MulTbigintBigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_TBIGINT_BIGINT */ case AntlrSQLLexer::MUL_TINT_INT: { @@ -1794,6 +1885,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: MUL_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: SUB_TBIGINT_BIGINT */ + case AntlrSQLLexer::SUB_TBIGINT_BIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_TBIGINT_BIGINT 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(SubTbigintBigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_TBIGINT_BIGINT */ case AntlrSQLLexer::SUB_TINT_INT: { From 6e878c9bf04fbae98b66f692d7ac06399768d804 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:29:36 +0200 Subject: [PATCH 14/20] feat(meos): add TBIGINT_SHIFT_VALUE, TBIGINT_SCALE_VALUE, TBIGINT_SHIFT_SCALE_VALUE NES operators (W56) --- .../Meos/TbigintScaleValueLogicalFunction.hpp | 54 +++++++++ .../TbigintShiftScaleValueLogicalFunction.hpp | 55 +++++++++ .../Meos/TbigintShiftValueLogicalFunction.hpp | 54 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../Meos/TbigintScaleValueLogicalFunction.cpp | 105 +++++++++++++++++ .../TbigintShiftScaleValueLogicalFunction.cpp | 108 ++++++++++++++++++ .../Meos/TbigintShiftValueLogicalFunction.cpp | 105 +++++++++++++++++ .../TbigintScaleValuePhysicalFunction.hpp | 44 +++++++ ...TbigintShiftScaleValuePhysicalFunction.hpp | 45 ++++++++ .../TbigintShiftValuePhysicalFunction.hpp | 44 +++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../TbigintScaleValuePhysicalFunction.cpp | 91 +++++++++++++++ ...TbigintShiftScaleValuePhysicalFunction.cpp | 95 +++++++++++++++ .../TbigintShiftValuePhysicalFunction.cpp | 91 +++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 5 +- .../src/AntlrSQLQueryPlanCreator.cpp | 91 +++++++++++++++ 16 files changed, 992 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/TbigintScaleValueLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TbigintShiftScaleValueLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TbigintShiftValueLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TbigintScaleValueLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TbigintShiftScaleValueLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TbigintShiftValueLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TbigintScaleValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TbigintShiftValuePhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TbigintScaleValuePhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TbigintShiftValuePhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TbigintScaleValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TbigintScaleValueLogicalFunction.hpp new file mode 100644 index 0000000000..5bac4a42f7 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TbigintScaleValueLogicalFunction.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 tbigint_scale_value: scales a single-instant tbigint to a given int64_t width. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tbigint_scale_value`. Takes (value:FLOAT64, ts:UINT64, width:FLOAT64→int64_t), + * constructs a single-instant temporal, applies the scale, and returns FLOAT64. + */ +class TbigintScaleValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TbigintScaleValue"; + + TbigintScaleValueLogicalFunction(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/TbigintShiftScaleValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TbigintShiftScaleValueLogicalFunction.hpp new file mode 100644 index 0000000000..5dde046e33 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TbigintShiftScaleValueLogicalFunction.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 tbigint_shift_scale_value: shifts and scales a single-instant tbigint. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tbigint_shift_scale_value`. Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64→int64_t, width:FLOAT64→int64_t), + * constructs a single-instant temporal, applies the shift-and-scale, and returns FLOAT64. + */ +class TbigintShiftScaleValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TbigintShiftScaleValue"; + + TbigintShiftScaleValueLogicalFunction(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/TbigintShiftValueLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TbigintShiftValueLogicalFunction.hpp new file mode 100644 index 0000000000..0944b75091 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TbigintShiftValueLogicalFunction.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 tbigint_shift_value: shifts a single-instant tbigint by a constant int64_t. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tbigint_shift_value`. Takes (value:FLOAT64, ts:UINT64, shift:FLOAT64→int64_t), + * constructs a single-instant temporal, applies the shift, and returns FLOAT64. + */ +class TbigintShiftValueLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TbigintShiftValue"; + + TbigintShiftValueLogicalFunction(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 58a9c60a18..dfd88823a8 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -51,6 +51,9 @@ 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(TbigintScaleValue LogicalFunction nes-logical-operators TbigintScaleValueLogicalFunction.cpp) +add_plugin(TbigintShiftScaleValue LogicalFunction nes-logical-operators TbigintShiftScaleValueLogicalFunction.cpp) +add_plugin(TbigintShiftValue LogicalFunction nes-logical-operators TbigintShiftValueLogicalFunction.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) diff --git a/nes-logical-operators/src/Functions/Meos/TbigintScaleValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TbigintScaleValueLogicalFunction.cpp new file mode 100644 index 0000000000..e8e23a4277 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TbigintScaleValueLogicalFunction.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 +{ + +TbigintScaleValueLogicalFunction::TbigintScaleValueLogicalFunction(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 TbigintScaleValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TbigintScaleValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TbigintScaleValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TbigintScaleValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TbigintScaleValueLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TbigintScaleValueLogicalFunction::getType() const { return NAME; } + +bool TbigintScaleValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TbigintScaleValueLogicalFunction::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 TbigintScaleValueLogicalFunction::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 TbigintScaleValueLogicalFunction::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::RegisterTbigintScaleValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TbigintScaleValueLogicalFunction 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 TbigintScaleValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TbigintShiftScaleValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TbigintShiftScaleValueLogicalFunction.cpp new file mode 100644 index 0000000000..ea572eba5d --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TbigintShiftScaleValueLogicalFunction.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 +{ + +TbigintShiftScaleValueLogicalFunction::TbigintShiftScaleValueLogicalFunction(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 TbigintShiftScaleValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TbigintShiftScaleValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TbigintShiftScaleValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TbigintShiftScaleValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 4, "TbigintShiftScaleValueLogicalFunction requires 4 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TbigintShiftScaleValueLogicalFunction::getType() const { return NAME; } + +bool TbigintShiftScaleValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TbigintShiftScaleValueLogicalFunction::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 TbigintShiftScaleValueLogicalFunction::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 TbigintShiftScaleValueLogicalFunction::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::RegisterTbigintShiftScaleValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 4, + "TbigintShiftScaleValueLogicalFunction 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 TbigintShiftScaleValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2), std::move(arg3)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TbigintShiftValueLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TbigintShiftValueLogicalFunction.cpp new file mode 100644 index 0000000000..090ac77e50 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TbigintShiftValueLogicalFunction.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 +{ + +TbigintShiftValueLogicalFunction::TbigintShiftValueLogicalFunction(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 TbigintShiftValueLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TbigintShiftValueLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TbigintShiftValueLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TbigintShiftValueLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "TbigintShiftValueLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TbigintShiftValueLogicalFunction::getType() const { return NAME; } + +bool TbigintShiftValueLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TbigintShiftValueLogicalFunction::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 TbigintShiftValueLogicalFunction::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 TbigintShiftValueLogicalFunction::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::RegisterTbigintShiftValueLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "TbigintShiftValueLogicalFunction 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 TbigintShiftValueLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TbigintScaleValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TbigintScaleValuePhysicalFunction.hpp new file mode 100644 index 0000000000..5965e5c4dc --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TbigintScaleValuePhysicalFunction.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 `tbigint_scale_value`. + * + * Per-event tbigint_scale_value: scales the value span of a single-instant tbigint + * to a given int64_t width. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TbigintScaleValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TbigintScaleValuePhysicalFunction(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/TbigintShiftScaleValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.hpp new file mode 100644 index 0000000000..63758b98e2 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.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 `tbigint_shift_scale_value`. + * + * Per-event tbigint_shift_scale_value: shifts the value span of a single-instant + * tbigint by a constant int64_t and scales it to the given int64_t width. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TbigintShiftScaleValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TbigintShiftScaleValuePhysicalFunction(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/TbigintShiftValuePhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TbigintShiftValuePhysicalFunction.hpp new file mode 100644 index 0000000000..7acf342692 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TbigintShiftValuePhysicalFunction.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 `tbigint_shift_value`. + * + * Per-event tbigint_shift_value: shifts the value span of a single-instant tbigint + * by a constant int64_t. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TbigintShiftValuePhysicalFunction : public PhysicalFunctionConcept { +public: + TbigintShiftValuePhysicalFunction(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 96feed49a1..0f6b6edc49 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -50,6 +50,9 @@ 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(TbigintScaleValue PhysicalFunction nes-physical-operators TbigintScaleValuePhysicalFunction.cpp) +add_plugin(TbigintShiftScaleValue PhysicalFunction nes-physical-operators TbigintShiftScaleValuePhysicalFunction.cpp) +add_plugin(TbigintShiftValue PhysicalFunction nes-physical-operators TbigintShiftValuePhysicalFunction.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) diff --git a/nes-physical-operators/src/Functions/Meos/TbigintScaleValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TbigintScaleValuePhysicalFunction.cpp new file mode 100644 index 0000000000..dc8c1fcfd9 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TbigintScaleValuePhysicalFunction.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 { + +TbigintScaleValuePhysicalFunction::TbigintScaleValuePhysicalFunction(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 TbigintScaleValuePhysicalFunction::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 = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tbigint_scale_value(temp, static_cast(width_d)); + 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, width); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTbigintScaleValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TbigintScaleValuePhysicalFunction 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 TbigintScaleValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.cpp new file mode 100644 index 0000000000..b0e2632357 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TbigintShiftScaleValuePhysicalFunction.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 { + +TbigintShiftScaleValuePhysicalFunction::TbigintShiftScaleValuePhysicalFunction(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 TbigintShiftScaleValuePhysicalFunction::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 = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tbigint_shift_scale_value(temp, static_cast(shift_d), static_cast(width_d)); + 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, shift, width); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTbigintShiftScaleValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 4, + "TbigintShiftScaleValuePhysicalFunction 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 TbigintShiftScaleValuePhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2), std::move(arg3)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TbigintShiftValuePhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TbigintShiftValuePhysicalFunction.cpp new file mode 100644 index 0000000000..c2d8da4f88 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TbigintShiftValuePhysicalFunction.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 { + +TbigintShiftValuePhysicalFunction::TbigintShiftValuePhysicalFunction(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 TbigintShiftValuePhysicalFunction::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 = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = tbigint_shift_value(temp, static_cast(shift_d)); + 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, shift); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterTbigintShiftValuePhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "TbigintShiftValuePhysicalFunction 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 TbigintShiftValuePhysicalFunction(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 390a9bf826..ed8e0abcec 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_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TBIGINT_BIGINT | 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; +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_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -504,6 +504,9 @@ SUB_TBIGINT_BIGINT: 'SUB_TBIGINT_BIGINT' | 'sub_tbigint_bigint'; 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_SCALE_VALUE: 'TBIGINT_SCALE_VALUE' | 'tbigint_scale_value'; +TBIGINT_SHIFT_SCALE_VALUE: 'TBIGINT_SHIFT_SCALE_VALUE' | 'tbigint_shift_scale_value'; +TBIGINT_SHIFT_VALUE: 'TBIGINT_SHIFT_VALUE' | 'tbigint_shift_value'; 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'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 065bc99553..4fab4d252e 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -85,6 +85,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -2060,6 +2063,94 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TNUMBER_TNUMBER */ + /* BEGIN CODEGEN PARSER GLUE: TBIGINT_SCALE_VALUE */ + case AntlrSQLLexer::TBIGINT_SCALE_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TBIGINT_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(TbigintScaleValueLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TBIGINT_SCALE_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TBIGINT_SHIFT_SCALE_VALUE */ + case AntlrSQLLexer::TBIGINT_SHIFT_SCALE_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 4) + throw InvalidQuerySyntax("TBIGINT_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(TbigintShiftScaleValueLogicalFunction(a0, a1, a2, a3)); + } + break; + /* END CODEGEN PARSER GLUE: TBIGINT_SHIFT_SCALE_VALUE */ + /* BEGIN CODEGEN PARSER GLUE: TBIGINT_SHIFT_VALUE */ + case AntlrSQLLexer::TBIGINT_SHIFT_VALUE: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("TBIGINT_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(TbigintShiftValueLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: TBIGINT_SHIFT_VALUE */ /* BEGIN CODEGEN PARSER GLUE: TBIGINT_TO_TFLOAT */ case AntlrSQLLexer::TBIGINT_TO_TFLOAT: { From 09eb3474aee3b0cd4e1b7dd3c168ea8f22b16dee Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:39:52 +0200 Subject: [PATCH 15/20] feat(meos): add ADD/SUB/MUL/DIV_FLOAT_TFLOAT reversed NES operators (W57) Adds per-event scalar NES operators for reversed-order float arithmetic on tfloat temporals: ADD_FLOAT_TFLOAT, SUB_FLOAT_TFLOAT, MUL_FLOAT_TFLOAT, DIV_FLOAT_TFLOAT. Each operator takes (scalar:float, value:float, ts:uint64) and delegates to the corresponding MEOS add_float_tfloat / sub_float_tfloat / mul_float_tfloat / div_float_tfloat kernel. --- .../Meos/AddFloatTfloatLogicalFunction.hpp | 54 ++++++++ .../Meos/DivFloatTfloatLogicalFunction.hpp | 54 ++++++++ .../Meos/MulFloatTfloatLogicalFunction.hpp | 54 ++++++++ .../Meos/SubFloatTfloatLogicalFunction.hpp | 54 ++++++++ .../Meos/AddFloatTfloatLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivFloatTfloatLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulFloatTfloatLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubFloatTfloatLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/AddFloatTfloatPhysicalFunction.hpp | 43 +++++++ .../Meos/DivFloatTfloatPhysicalFunction.hpp | 43 +++++++ .../Meos/MulFloatTfloatPhysicalFunction.hpp | 43 +++++++ .../Meos/SubFloatTfloatPhysicalFunction.hpp | 43 +++++++ .../Meos/AddFloatTfloatPhysicalFunction.cpp | 91 +++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivFloatTfloatPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/MulFloatTfloatPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/SubFloatTfloatPhysicalFunction.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/AddFloatTfloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivFloatTfloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulFloatTfloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubFloatTfloatLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddFloatTfloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivFloatTfloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulFloatTfloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubFloatTfloatLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddFloatTfloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivFloatTfloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulFloatTfloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubFloatTfloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddFloatTfloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivFloatTfloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulFloatTfloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubFloatTfloatPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddFloatTfloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddFloatTfloatLogicalFunction.hpp new file mode 100644 index 0000000000..1454a1dc3a --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddFloatTfloatLogicalFunction.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_float_tfloat: adds a constant to a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_float_tfloat`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the addition, and returns FLOAT64. + */ +class AddFloatTfloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddFloatTfloat"; + + AddFloatTfloatLogicalFunction(LogicalFunction scalar, + 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/DivFloatTfloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivFloatTfloatLogicalFunction.hpp new file mode 100644 index 0000000000..78060cbec2 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivFloatTfloatLogicalFunction.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_float_tfloat: divides a constant by a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_float_tfloat`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the division, and returns FLOAT64. + */ +class DivFloatTfloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivFloatTfloat"; + + DivFloatTfloatLogicalFunction(LogicalFunction scalar, + 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/MulFloatTfloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulFloatTfloatLogicalFunction.hpp new file mode 100644 index 0000000000..c4f788803b --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulFloatTfloatLogicalFunction.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_float_tfloat: multiplies a constant by a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_float_tfloat`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the multiplication, and returns FLOAT64. + */ +class MulFloatTfloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulFloatTfloat"; + + MulFloatTfloatLogicalFunction(LogicalFunction scalar, + 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/SubFloatTfloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubFloatTfloatLogicalFunction.hpp new file mode 100644 index 0000000000..a0ec1c5683 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubFloatTfloatLogicalFunction.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_float_tfloat: subtracts a single-instant tfloat value from a constant. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_float_tfloat`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the subtraction, and returns FLOAT64. + */ +class SubFloatTfloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubFloatTfloat"; + + SubFloatTfloatLogicalFunction(LogicalFunction scalar, + 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/AddFloatTfloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddFloatTfloatLogicalFunction.cpp new file mode 100644 index 0000000000..80d3f44e21 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddFloatTfloatLogicalFunction.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 +{ + +AddFloatTfloatLogicalFunction::AddFloatTfloatLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType AddFloatTfloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddFloatTfloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddFloatTfloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddFloatTfloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddFloatTfloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddFloatTfloatLogicalFunction::getType() const { return NAME; } + +bool AddFloatTfloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddFloatTfloatLogicalFunction::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 AddFloatTfloatLogicalFunction::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 AddFloatTfloatLogicalFunction::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::RegisterAddFloatTfloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddFloatTfloatLogicalFunction 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 AddFloatTfloatLogicalFunction(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 dfd88823a8..1c4f89f633 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -24,6 +24,7 @@ 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(AddFloatTfloat LogicalFunction nes-logical-operators AddFloatTfloatLogicalFunction.cpp) add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) add_plugin(AddTbigintBigint LogicalFunction nes-logical-operators AddTbigintBigintLogicalFunction.cpp) add_plugin(AddTintInt LogicalFunction nes-logical-operators AddTintIntLogicalFunction.cpp) @@ -44,8 +45,11 @@ add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnu add_plugin(SubTbigintBigint LogicalFunction nes-logical-operators SubTbigintBigintLogicalFunction.cpp) add_plugin(SubTintInt LogicalFunction nes-logical-operators SubTintIntLogicalFunction.cpp) add_plugin(SubTnumberTnumber LogicalFunction nes-logical-operators SubTnumberTnumberLogicalFunction.cpp) +add_plugin(DivFloatTfloat LogicalFunction nes-logical-operators DivFloatTfloatLogicalFunction.cpp) add_plugin(DivTfloatFloat LogicalFunction nes-logical-operators DivTfloatFloatLogicalFunction.cpp) +add_plugin(MulFloatTfloat LogicalFunction nes-logical-operators MulFloatTfloatLogicalFunction.cpp) add_plugin(MulTfloatFloat LogicalFunction nes-logical-operators MulTfloatFloatLogicalFunction.cpp) +add_plugin(SubFloatTfloat LogicalFunction nes-logical-operators SubFloatTfloatLogicalFunction.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) diff --git a/nes-logical-operators/src/Functions/Meos/DivFloatTfloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivFloatTfloatLogicalFunction.cpp new file mode 100644 index 0000000000..321d299422 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivFloatTfloatLogicalFunction.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 +{ + +DivFloatTfloatLogicalFunction::DivFloatTfloatLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType DivFloatTfloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivFloatTfloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivFloatTfloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivFloatTfloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivFloatTfloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivFloatTfloatLogicalFunction::getType() const { return NAME; } + +bool DivFloatTfloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivFloatTfloatLogicalFunction::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 DivFloatTfloatLogicalFunction::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 DivFloatTfloatLogicalFunction::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::RegisterDivFloatTfloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivFloatTfloatLogicalFunction 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 DivFloatTfloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulFloatTfloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulFloatTfloatLogicalFunction.cpp new file mode 100644 index 0000000000..7a38b56a88 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulFloatTfloatLogicalFunction.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 +{ + +MulFloatTfloatLogicalFunction::MulFloatTfloatLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType MulFloatTfloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulFloatTfloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulFloatTfloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulFloatTfloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulFloatTfloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulFloatTfloatLogicalFunction::getType() const { return NAME; } + +bool MulFloatTfloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulFloatTfloatLogicalFunction::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 MulFloatTfloatLogicalFunction::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 MulFloatTfloatLogicalFunction::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::RegisterMulFloatTfloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulFloatTfloatLogicalFunction 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 MulFloatTfloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubFloatTfloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubFloatTfloatLogicalFunction.cpp new file mode 100644 index 0000000000..30d298ffb2 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubFloatTfloatLogicalFunction.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 +{ + +SubFloatTfloatLogicalFunction::SubFloatTfloatLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType SubFloatTfloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubFloatTfloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubFloatTfloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubFloatTfloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubFloatTfloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubFloatTfloatLogicalFunction::getType() const { return NAME; } + +bool SubFloatTfloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubFloatTfloatLogicalFunction::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 SubFloatTfloatLogicalFunction::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 SubFloatTfloatLogicalFunction::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::RegisterSubFloatTfloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubFloatTfloatLogicalFunction 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 SubFloatTfloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddFloatTfloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddFloatTfloatPhysicalFunction.hpp new file mode 100644 index 0000000000..8c37def1c6 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddFloatTfloatPhysicalFunction.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_float_tfloat`. + * + * Per-event add_float_tfloat: adds a constant to a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddFloatTfloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AddFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + 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/DivFloatTfloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivFloatTfloatPhysicalFunction.hpp new file mode 100644 index 0000000000..3ac3044b9b --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivFloatTfloatPhysicalFunction.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_float_tfloat`. + * + * Per-event div_float_tfloat: divides a constant by a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivFloatTfloatPhysicalFunction : public PhysicalFunctionConcept { +public: + DivFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + 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/MulFloatTfloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulFloatTfloatPhysicalFunction.hpp new file mode 100644 index 0000000000..c9b029f509 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulFloatTfloatPhysicalFunction.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_float_tfloat`. + * + * Per-event mul_float_tfloat: multiplies a constant by a single-instant tfloat value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulFloatTfloatPhysicalFunction : public PhysicalFunctionConcept { +public: + MulFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + 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/SubFloatTfloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubFloatTfloatPhysicalFunction.hpp new file mode 100644 index 0000000000..bc997c36cc --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubFloatTfloatPhysicalFunction.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_float_tfloat`. + * + * Per-event sub_float_tfloat: subtracts a single-instant tfloat value from a constant. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubFloatTfloatPhysicalFunction : public PhysicalFunctionConcept { +public: + SubFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + 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/AddFloatTfloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddFloatTfloatPhysicalFunction.cpp new file mode 100644 index 0000000000..50cf48bbf9 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddFloatTfloatPhysicalFunction.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 { + +AddFloatTfloatPhysicalFunction::AddFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AddFloatTfloatPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar, 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 = add_float_tfloat(scalar, 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddFloatTfloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddFloatTfloatPhysicalFunction 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 AddFloatTfloatPhysicalFunction(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 0f6b6edc49..68e4937d0f 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -23,6 +23,7 @@ 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(AddFloatTfloat PhysicalFunction nes-physical-operators AddFloatTfloatPhysicalFunction.cpp) add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) add_plugin(AddTbigintBigint PhysicalFunction nes-physical-operators AddTbigintBigintPhysicalFunction.cpp) add_plugin(AddTintInt PhysicalFunction nes-physical-operators AddTintIntPhysicalFunction.cpp) @@ -43,8 +44,11 @@ add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberT add_plugin(SubTbigintBigint PhysicalFunction nes-physical-operators SubTbigintBigintPhysicalFunction.cpp) add_plugin(SubTintInt PhysicalFunction nes-physical-operators SubTintIntPhysicalFunction.cpp) add_plugin(SubTnumberTnumber PhysicalFunction nes-physical-operators SubTnumberTnumberPhysicalFunction.cpp) +add_plugin(DivFloatTfloat PhysicalFunction nes-physical-operators DivFloatTfloatPhysicalFunction.cpp) add_plugin(DivTfloatFloat PhysicalFunction nes-physical-operators DivTfloatFloatPhysicalFunction.cpp) +add_plugin(MulFloatTfloat PhysicalFunction nes-physical-operators MulFloatTfloatPhysicalFunction.cpp) add_plugin(MulTfloatFloat PhysicalFunction nes-physical-operators MulTfloatFloatPhysicalFunction.cpp) +add_plugin(SubFloatTfloat PhysicalFunction nes-physical-operators SubFloatTfloatPhysicalFunction.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) diff --git a/nes-physical-operators/src/Functions/Meos/DivFloatTfloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivFloatTfloatPhysicalFunction.cpp new file mode 100644 index 0000000000..f920a90108 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivFloatTfloatPhysicalFunction.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 { + +DivFloatTfloatPhysicalFunction::DivFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal DivFloatTfloatPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar, 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 = div_float_tfloat(scalar, 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivFloatTfloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivFloatTfloatPhysicalFunction 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 DivFloatTfloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulFloatTfloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulFloatTfloatPhysicalFunction.cpp new file mode 100644 index 0000000000..94fe98aa57 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulFloatTfloatPhysicalFunction.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 { + +MulFloatTfloatPhysicalFunction::MulFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal MulFloatTfloatPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar, 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 = mul_float_tfloat(scalar, 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulFloatTfloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulFloatTfloatPhysicalFunction 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 MulFloatTfloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubFloatTfloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubFloatTfloatPhysicalFunction.cpp new file mode 100644 index 0000000000..1f4e5254ac --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubFloatTfloatPhysicalFunction.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 { + +SubFloatTfloatPhysicalFunction::SubFloatTfloatPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal SubFloatTfloatPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar, 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 = sub_float_tfloat(scalar, 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubFloatTfloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubFloatTfloatPhysicalFunction 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 SubFloatTfloatPhysicalFunction(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 ed8e0abcec..674ef5c733 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_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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; +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_FLOAT_TFLOAT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_FLOAT_TFLOAT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_FLOAT_TFLOAT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_FLOAT_TFLOAT | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -488,18 +488,22 @@ 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_FLOAT_TFLOAT: 'ADD_FLOAT_TFLOAT' | 'add_float_tfloat'; ADD_TBIGINT_BIGINT: 'ADD_TBIGINT_BIGINT' | 'add_tbigint_bigint'; 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_FLOAT_TFLOAT: 'DIV_FLOAT_TFLOAT' | 'div_float_tfloat'; DIV_TBIGINT_BIGINT: 'DIV_TBIGINT_BIGINT' | 'div_tbigint_bigint'; 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_FLOAT_TFLOAT: 'MUL_FLOAT_TFLOAT' | 'mul_float_tfloat'; MUL_TBIGINT_BIGINT: 'MUL_TBIGINT_BIGINT' | 'mul_tbigint_bigint'; 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_FLOAT_TFLOAT: 'SUB_FLOAT_TFLOAT' | 'sub_float_tfloat'; SUB_TBIGINT_BIGINT: 'SUB_TBIGINT_BIGINT' | 'sub_tbigint_bigint'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; SUB_TINT_INT: 'SUB_TINT_INT' | 'sub_tint_int'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 4fab4d252e..06f381369f 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -69,18 +69,22 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -1598,6 +1602,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TNUMBER_ABS */ + /* BEGIN CODEGEN PARSER GLUE: ADD_FLOAT_TFLOAT */ + case AntlrSQLLexer::ADD_FLOAT_TFLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_FLOAT_TFLOAT 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(AddFloatTfloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_FLOAT_TFLOAT */ /* BEGIN CODEGEN PARSER GLUE: ADD_TFLOAT_FLOAT */ case AntlrSQLLexer::ADD_TFLOAT_FLOAT: { @@ -1627,6 +1660,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: ADD_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: DIV_FLOAT_TFLOAT */ + case AntlrSQLLexer::DIV_FLOAT_TFLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_FLOAT_TFLOAT 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(DivFloatTfloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_FLOAT_TFLOAT */ /* BEGIN CODEGEN PARSER GLUE: DIV_TFLOAT_FLOAT */ case AntlrSQLLexer::DIV_TFLOAT_FLOAT: { @@ -1656,6 +1718,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: DIV_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: MUL_FLOAT_TFLOAT */ + case AntlrSQLLexer::MUL_FLOAT_TFLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_FLOAT_TFLOAT 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(MulFloatTfloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_FLOAT_TFLOAT */ /* BEGIN CODEGEN PARSER GLUE: MUL_TFLOAT_FLOAT */ case AntlrSQLLexer::MUL_TFLOAT_FLOAT: { @@ -1685,6 +1776,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: MUL_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: SUB_FLOAT_TFLOAT */ + case AntlrSQLLexer::SUB_FLOAT_TFLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_FLOAT_TFLOAT 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(SubFloatTfloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_FLOAT_TFLOAT */ /* BEGIN CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ case AntlrSQLLexer::SUB_TFLOAT_FLOAT: { From e7a09dc598f6576734f94dc4babdb32c694e6c25 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:46:22 +0200 Subject: [PATCH 16/20] feat(meos): add ADD/SUB/MUL/DIV_INT_TINT reversed NES operators (W58) Adds per-event scalar NES operators for reversed-order integer arithmetic on tint temporals: ADD_INT_TINT, SUB_INT_TINT, MUL_INT_TINT, DIV_INT_TINT. Each operator takes (scalar:int, value:int, ts:uint64) and delegates to the corresponding MEOS add_int_tint / sub_int_tint / mul_int_tint / div_int_tint kernel. --- .../Meos/AddIntTintLogicalFunction.hpp | 54 ++++++++ .../Meos/DivIntTintLogicalFunction.hpp | 54 ++++++++ .../Meos/MulIntTintLogicalFunction.hpp | 54 ++++++++ .../Meos/SubIntTintLogicalFunction.hpp | 54 ++++++++ .../Meos/AddIntTintLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivIntTintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulIntTintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubIntTintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/AddIntTintPhysicalFunction.hpp | 43 +++++++ .../Meos/DivIntTintPhysicalFunction.hpp | 43 +++++++ .../Meos/MulIntTintPhysicalFunction.hpp | 43 +++++++ .../Meos/SubIntTintPhysicalFunction.hpp | 43 +++++++ .../Meos/AddIntTintPhysicalFunction.cpp | 91 +++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivIntTintPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/MulIntTintPhysicalFunction.cpp | 91 +++++++++++++ .../Meos/SubIntTintPhysicalFunction.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/AddIntTintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivIntTintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulIntTintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubIntTintLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddIntTintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivIntTintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulIntTintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubIntTintLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddIntTintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivIntTintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulIntTintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubIntTintPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddIntTintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivIntTintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulIntTintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubIntTintPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddIntTintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddIntTintLogicalFunction.hpp new file mode 100644 index 0000000000..db3ef60e22 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddIntTintLogicalFunction.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_int_tint: adds a constant to a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_int_tint`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the addition, and returns FLOAT64. + */ +class AddIntTintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddIntTint"; + + AddIntTintLogicalFunction(LogicalFunction scalar, + 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/DivIntTintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivIntTintLogicalFunction.hpp new file mode 100644 index 0000000000..f48f877b8b --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivIntTintLogicalFunction.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_int_tint: divides a constant by a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_int_tint`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the division, and returns FLOAT64. + */ +class DivIntTintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivIntTint"; + + DivIntTintLogicalFunction(LogicalFunction scalar, + 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/MulIntTintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulIntTintLogicalFunction.hpp new file mode 100644 index 0000000000..a2f0f7f2b3 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulIntTintLogicalFunction.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_int_tint: multiplies a constant by a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_int_tint`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the multiplication, and returns FLOAT64. + */ +class MulIntTintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulIntTint"; + + MulIntTintLogicalFunction(LogicalFunction scalar, + 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/SubIntTintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubIntTintLogicalFunction.hpp new file mode 100644 index 0000000000..5e3f4a8c94 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubIntTintLogicalFunction.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_int_tint: subtracts a single-instant tint value from a constant. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_int_tint`. Takes (scalar:FLOAT64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the subtraction, and returns FLOAT64. + */ +class SubIntTintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubIntTint"; + + SubIntTintLogicalFunction(LogicalFunction scalar, + 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/AddIntTintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddIntTintLogicalFunction.cpp new file mode 100644 index 0000000000..184848e839 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddIntTintLogicalFunction.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 +{ + +AddIntTintLogicalFunction::AddIntTintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType AddIntTintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddIntTintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddIntTintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddIntTintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddIntTintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddIntTintLogicalFunction::getType() const { return NAME; } + +bool AddIntTintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddIntTintLogicalFunction::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 AddIntTintLogicalFunction::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 AddIntTintLogicalFunction::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::RegisterAddIntTintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddIntTintLogicalFunction 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 AddIntTintLogicalFunction(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 1c4f89f633..b183f783d5 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -27,6 +27,7 @@ add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleVal add_plugin(AddFloatTfloat LogicalFunction nes-logical-operators AddFloatTfloatLogicalFunction.cpp) add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) add_plugin(AddTbigintBigint LogicalFunction nes-logical-operators AddTbigintBigintLogicalFunction.cpp) +add_plugin(AddIntTint LogicalFunction nes-logical-operators AddIntTintLogicalFunction.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) @@ -37,12 +38,15 @@ add_plugin(TintScaleValue LogicalFunction nes-logical-operators TintScaleValueLo add_plugin(TintShiftScaleValue LogicalFunction nes-logical-operators TintShiftScaleValueLogicalFunction.cpp) add_plugin(TintShiftValue LogicalFunction nes-logical-operators TintShiftValueLogicalFunction.cpp) add_plugin(DivTbigintBigint LogicalFunction nes-logical-operators DivTbigintBigintLogicalFunction.cpp) +add_plugin(DivIntTint LogicalFunction nes-logical-operators DivIntTintLogicalFunction.cpp) add_plugin(DivTintInt LogicalFunction nes-logical-operators DivTintIntLogicalFunction.cpp) add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) add_plugin(MulTbigintBigint LogicalFunction nes-logical-operators MulTbigintBigintLogicalFunction.cpp) +add_plugin(MulIntTint LogicalFunction nes-logical-operators MulIntTintLogicalFunction.cpp) add_plugin(MulTintInt LogicalFunction nes-logical-operators MulTintIntLogicalFunction.cpp) add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnumberLogicalFunction.cpp) add_plugin(SubTbigintBigint LogicalFunction nes-logical-operators SubTbigintBigintLogicalFunction.cpp) +add_plugin(SubIntTint LogicalFunction nes-logical-operators SubIntTintLogicalFunction.cpp) add_plugin(SubTintInt LogicalFunction nes-logical-operators SubTintIntLogicalFunction.cpp) add_plugin(SubTnumberTnumber LogicalFunction nes-logical-operators SubTnumberTnumberLogicalFunction.cpp) add_plugin(DivFloatTfloat LogicalFunction nes-logical-operators DivFloatTfloatLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/DivIntTintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivIntTintLogicalFunction.cpp new file mode 100644 index 0000000000..5abd6ce582 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivIntTintLogicalFunction.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 +{ + +DivIntTintLogicalFunction::DivIntTintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType DivIntTintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivIntTintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivIntTintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivIntTintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivIntTintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivIntTintLogicalFunction::getType() const { return NAME; } + +bool DivIntTintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivIntTintLogicalFunction::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 DivIntTintLogicalFunction::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 DivIntTintLogicalFunction::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::RegisterDivIntTintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivIntTintLogicalFunction 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 DivIntTintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulIntTintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulIntTintLogicalFunction.cpp new file mode 100644 index 0000000000..6b5cc688ee --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulIntTintLogicalFunction.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 +{ + +MulIntTintLogicalFunction::MulIntTintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType MulIntTintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulIntTintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulIntTintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulIntTintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulIntTintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulIntTintLogicalFunction::getType() const { return NAME; } + +bool MulIntTintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulIntTintLogicalFunction::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 MulIntTintLogicalFunction::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 MulIntTintLogicalFunction::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::RegisterMulIntTintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulIntTintLogicalFunction 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 MulIntTintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubIntTintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubIntTintLogicalFunction.cpp new file mode 100644 index 0000000000..137088701d --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubIntTintLogicalFunction.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 +{ + +SubIntTintLogicalFunction::SubIntTintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType SubIntTintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubIntTintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubIntTintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubIntTintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubIntTintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubIntTintLogicalFunction::getType() const { return NAME; } + +bool SubIntTintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubIntTintLogicalFunction::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 SubIntTintLogicalFunction::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 SubIntTintLogicalFunction::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::RegisterSubIntTintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubIntTintLogicalFunction 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 SubIntTintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddIntTintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddIntTintPhysicalFunction.hpp new file mode 100644 index 0000000000..086b9058c2 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddIntTintPhysicalFunction.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_int_tint`. + * + * Per-event add_int_tint: adds a constant to a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddIntTintPhysicalFunction : public PhysicalFunctionConcept { +public: + AddIntTintPhysicalFunction(PhysicalFunction scalarFunction, + 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/DivIntTintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivIntTintPhysicalFunction.hpp new file mode 100644 index 0000000000..e368a96708 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivIntTintPhysicalFunction.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_int_tint`. + * + * Per-event div_int_tint: divides a constant by a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivIntTintPhysicalFunction : public PhysicalFunctionConcept { +public: + DivIntTintPhysicalFunction(PhysicalFunction scalarFunction, + 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/MulIntTintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulIntTintPhysicalFunction.hpp new file mode 100644 index 0000000000..c5799619f8 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulIntTintPhysicalFunction.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_int_tint`. + * + * Per-event mul_int_tint: multiplies a constant by a single-instant tint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulIntTintPhysicalFunction : public PhysicalFunctionConcept { +public: + MulIntTintPhysicalFunction(PhysicalFunction scalarFunction, + 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/SubIntTintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubIntTintPhysicalFunction.hpp new file mode 100644 index 0000000000..051774283e --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubIntTintPhysicalFunction.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_int_tint`. + * + * Per-event sub_int_tint: subtracts a single-instant tint value from a constant. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubIntTintPhysicalFunction : public PhysicalFunctionConcept { +public: + SubIntTintPhysicalFunction(PhysicalFunction scalarFunction, + 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/AddIntTintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddIntTintPhysicalFunction.cpp new file mode 100644 index 0000000000..f6cb83b692 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddIntTintPhysicalFunction.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 { + +AddIntTintPhysicalFunction::AddIntTintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AddIntTintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = add_int_tint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddIntTintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddIntTintPhysicalFunction 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 AddIntTintPhysicalFunction(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 68e4937d0f..d6ede70801 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -26,6 +26,7 @@ add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleV add_plugin(AddFloatTfloat PhysicalFunction nes-physical-operators AddFloatTfloatPhysicalFunction.cpp) add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) add_plugin(AddTbigintBigint PhysicalFunction nes-physical-operators AddTbigintBigintPhysicalFunction.cpp) +add_plugin(AddIntTint PhysicalFunction nes-physical-operators AddIntTintPhysicalFunction.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) @@ -36,12 +37,15 @@ add_plugin(TintScaleValue PhysicalFunction nes-physical-operators TintScaleValue add_plugin(TintShiftScaleValue PhysicalFunction nes-physical-operators TintShiftScaleValuePhysicalFunction.cpp) add_plugin(TintShiftValue PhysicalFunction nes-physical-operators TintShiftValuePhysicalFunction.cpp) add_plugin(DivTbigintBigint PhysicalFunction nes-physical-operators DivTbigintBigintPhysicalFunction.cpp) +add_plugin(DivIntTint PhysicalFunction nes-physical-operators DivIntTintPhysicalFunction.cpp) add_plugin(DivTintInt PhysicalFunction nes-physical-operators DivTintIntPhysicalFunction.cpp) add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) add_plugin(MulTbigintBigint PhysicalFunction nes-physical-operators MulTbigintBigintPhysicalFunction.cpp) +add_plugin(MulIntTint PhysicalFunction nes-physical-operators MulIntTintPhysicalFunction.cpp) add_plugin(MulTintInt PhysicalFunction nes-physical-operators MulTintIntPhysicalFunction.cpp) add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberTnumberPhysicalFunction.cpp) add_plugin(SubTbigintBigint PhysicalFunction nes-physical-operators SubTbigintBigintPhysicalFunction.cpp) +add_plugin(SubIntTint PhysicalFunction nes-physical-operators SubIntTintPhysicalFunction.cpp) add_plugin(SubTintInt PhysicalFunction nes-physical-operators SubTintIntPhysicalFunction.cpp) add_plugin(SubTnumberTnumber PhysicalFunction nes-physical-operators SubTnumberTnumberPhysicalFunction.cpp) add_plugin(DivFloatTfloat PhysicalFunction nes-physical-operators DivFloatTfloatPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/DivIntTintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivIntTintPhysicalFunction.cpp new file mode 100644 index 0000000000..d612334db7 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivIntTintPhysicalFunction.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 { + +DivIntTintPhysicalFunction::DivIntTintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal DivIntTintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = div_int_tint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivIntTintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivIntTintPhysicalFunction 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 DivIntTintPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulIntTintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulIntTintPhysicalFunction.cpp new file mode 100644 index 0000000000..19b58599e9 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulIntTintPhysicalFunction.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 { + +MulIntTintPhysicalFunction::MulIntTintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal MulIntTintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = mul_int_tint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulIntTintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulIntTintPhysicalFunction 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 MulIntTintPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubIntTintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubIntTintPhysicalFunction.cpp new file mode 100644 index 0000000000..07f4ec11c7 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubIntTintPhysicalFunction.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 { + +SubIntTintPhysicalFunction::SubIntTintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal SubIntTintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = sub_int_tint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubIntTintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubIntTintPhysicalFunction 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 SubIntTintPhysicalFunction(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 674ef5c733..e38329c1d3 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_FLOAT_TFLOAT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_FLOAT_TFLOAT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_FLOAT_TFLOAT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_FLOAT_TFLOAT | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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; +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_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -491,21 +491,25 @@ TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; ADD_FLOAT_TFLOAT: 'ADD_FLOAT_TFLOAT' | 'add_float_tfloat'; ADD_TBIGINT_BIGINT: 'ADD_TBIGINT_BIGINT' | 'add_tbigint_bigint'; ADD_TFLOAT_FLOAT: 'ADD_TFLOAT_FLOAT' | 'add_tfloat_float'; +ADD_INT_TINT: 'ADD_INT_TINT' | 'add_int_tint'; ADD_TINT_INT: 'ADD_TINT_INT' | 'add_tint_int'; ADD_TNUMBER_TNUMBER: 'ADD_TNUMBER_TNUMBER' | 'add_tnumber_tnumber'; DIV_FLOAT_TFLOAT: 'DIV_FLOAT_TFLOAT' | 'div_float_tfloat'; DIV_TBIGINT_BIGINT: 'DIV_TBIGINT_BIGINT' | 'div_tbigint_bigint'; DIV_TFLOAT_FLOAT: 'DIV_TFLOAT_FLOAT' | 'div_tfloat_float'; +DIV_INT_TINT: 'DIV_INT_TINT' | 'div_int_tint'; DIV_TINT_INT: 'DIV_TINT_INT' | 'div_tint_int'; DIV_TNUMBER_TNUMBER: 'DIV_TNUMBER_TNUMBER' | 'div_tnumber_tnumber'; MUL_FLOAT_TFLOAT: 'MUL_FLOAT_TFLOAT' | 'mul_float_tfloat'; MUL_TBIGINT_BIGINT: 'MUL_TBIGINT_BIGINT' | 'mul_tbigint_bigint'; MUL_TFLOAT_FLOAT: 'MUL_TFLOAT_FLOAT' | 'mul_tfloat_float'; +MUL_INT_TINT: 'MUL_INT_TINT' | 'mul_int_tint'; MUL_TINT_INT: 'MUL_TINT_INT' | 'mul_tint_int'; MUL_TNUMBER_TNUMBER: 'MUL_TNUMBER_TNUMBER' | 'mul_tnumber_tnumber'; SUB_FLOAT_TFLOAT: 'SUB_FLOAT_TFLOAT' | 'sub_float_tfloat'; SUB_TBIGINT_BIGINT: 'SUB_TBIGINT_BIGINT' | 'sub_tbigint_bigint'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; +SUB_INT_TINT: 'SUB_INT_TINT' | 'sub_int_tint'; SUB_TINT_INT: 'SUB_TINT_INT' | 'sub_tint_int'; SUB_TNUMBER_TNUMBER: 'SUB_TNUMBER_TNUMBER' | 'sub_tnumber_tnumber'; TBIGINT_SCALE_VALUE: 'TBIGINT_SCALE_VALUE' | 'tbigint_scale_value'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 06f381369f..c7666a5cdc 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -72,21 +72,25 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -1863,6 +1867,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: ADD_TBIGINT_BIGINT */ + /* BEGIN CODEGEN PARSER GLUE: ADD_INT_TINT */ + case AntlrSQLLexer::ADD_INT_TINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_INT_TINT 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(AddIntTintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_INT_TINT */ case AntlrSQLLexer::ADD_TINT_INT: { @@ -1921,6 +1954,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: DIV_TBIGINT_BIGINT */ + /* BEGIN CODEGEN PARSER GLUE: DIV_INT_TINT */ + case AntlrSQLLexer::DIV_INT_TINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_INT_TINT 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(DivIntTintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_INT_TINT */ case AntlrSQLLexer::DIV_TINT_INT: { @@ -1979,6 +2041,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: MUL_TBIGINT_BIGINT */ + /* BEGIN CODEGEN PARSER GLUE: MUL_INT_TINT */ + case AntlrSQLLexer::MUL_INT_TINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_INT_TINT 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(MulIntTintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_INT_TINT */ case AntlrSQLLexer::MUL_TINT_INT: { @@ -2037,6 +2128,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TBIGINT_BIGINT */ + /* BEGIN CODEGEN PARSER GLUE: SUB_INT_TINT */ + case AntlrSQLLexer::SUB_INT_TINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_INT_TINT 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(SubIntTintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_INT_TINT */ case AntlrSQLLexer::SUB_TINT_INT: { From 8a4f6c9a9465c53cb9e23a277dc1a930b6d58b2b Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 06:53:10 +0200 Subject: [PATCH 17/20] feat(meos): add ADD/SUB/MUL/DIV_BIGINT_TBIGINT reversed NES operators (W59) Adds per-event scalar NES operators for reversed-order bigint arithmetic on tbigint temporals: ADD_BIGINT_TBIGINT, SUB_BIGINT_TBIGINT, MUL_BIGINT_TBIGINT, DIV_BIGINT_TBIGINT. Each operator takes (scalar:bigint, value:bigint, ts:uint64) and delegates to the corresponding MEOS add_bigint_tbigint / sub_bigint_tbigint / mul_bigint_tbigint / div_bigint_tbigint kernel. --- .../Meos/AddBigintTbigintLogicalFunction.hpp | 54 ++++++++ .../Meos/DivBigintTbigintLogicalFunction.hpp | 54 ++++++++ .../Meos/MulBigintTbigintLogicalFunction.hpp | 54 ++++++++ .../Meos/SubBigintTbigintLogicalFunction.hpp | 54 ++++++++ .../Meos/AddBigintTbigintLogicalFunction.cpp | 105 +++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivBigintTbigintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/MulBigintTbigintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/SubBigintTbigintLogicalFunction.cpp | 105 +++++++++++++++ .../Meos/AddBigintTbigintPhysicalFunction.hpp | 43 +++++++ .../Meos/DivBigintTbigintPhysicalFunction.hpp | 43 +++++++ .../Meos/MulBigintTbigintPhysicalFunction.hpp | 43 +++++++ .../Meos/SubBigintTbigintPhysicalFunction.hpp | 43 +++++++ .../Meos/AddBigintTbigintPhysicalFunction.cpp | 92 ++++++++++++++ .../src/Functions/Meos/CMakeLists.txt | 4 + .../Meos/DivBigintTbigintPhysicalFunction.cpp | 92 ++++++++++++++ .../Meos/MulBigintTbigintPhysicalFunction.cpp | 92 ++++++++++++++ .../Meos/SubBigintTbigintPhysicalFunction.cpp | 92 ++++++++++++++ nes-sql-parser/AntlrSQL.g4 | 6 +- .../src/AntlrSQLQueryPlanCreator.cpp | 120 ++++++++++++++++++ 20 files changed, 1309 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/AddBigintTbigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/DivBigintTbigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/MulBigintTbigintLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/SubBigintTbigintLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AddBigintTbigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/DivBigintTbigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/MulBigintTbigintLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/SubBigintTbigintLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AddBigintTbigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/DivBigintTbigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/MulBigintTbigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/SubBigintTbigintPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AddBigintTbigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/DivBigintTbigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/MulBigintTbigintPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/SubBigintTbigintPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AddBigintTbigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AddBigintTbigintLogicalFunction.hpp new file mode 100644 index 0000000000..99a8dcb629 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AddBigintTbigintLogicalFunction.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_bigint_tbigint: adds a constant int64 scalar to a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `add_bigint_tbigint`. Takes (scalar:FLOAT64→int64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the addition, and returns FLOAT64. + */ +class AddBigintTbigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AddBigintTbigint"; + + AddBigintTbigintLogicalFunction(LogicalFunction scalar, + 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/DivBigintTbigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/DivBigintTbigintLogicalFunction.hpp new file mode 100644 index 0000000000..993b9666e1 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/DivBigintTbigintLogicalFunction.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_bigint_tbigint: divides a constant int64 scalar by a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `div_bigint_tbigint`. Takes (scalar:FLOAT64→int64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the division, and returns FLOAT64. + */ +class DivBigintTbigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "DivBigintTbigint"; + + DivBigintTbigintLogicalFunction(LogicalFunction scalar, + 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/MulBigintTbigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/MulBigintTbigintLogicalFunction.hpp new file mode 100644 index 0000000000..bc3e2244f5 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/MulBigintTbigintLogicalFunction.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_bigint_tbigint: multiplies a constant int64 scalar by a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `mul_bigint_tbigint`. Takes (scalar:FLOAT64→int64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the multiplication, and returns FLOAT64. + */ +class MulBigintTbigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "MulBigintTbigint"; + + MulBigintTbigintLogicalFunction(LogicalFunction scalar, + 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/SubBigintTbigintLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/SubBigintTbigintLogicalFunction.hpp new file mode 100644 index 0000000000..dfd0d17747 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/SubBigintTbigintLogicalFunction.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_bigint_tbigint: subtracts a single-instant tbigint value from a constant int64 scalar. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `sub_bigint_tbigint`. Takes (scalar:FLOAT64→int64, value:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the subtraction, and returns FLOAT64. + */ +class SubBigintTbigintLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "SubBigintTbigint"; + + SubBigintTbigintLogicalFunction(LogicalFunction scalar, + 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/AddBigintTbigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AddBigintTbigintLogicalFunction.cpp new file mode 100644 index 0000000000..4c0eae2820 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AddBigintTbigintLogicalFunction.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 +{ + +AddBigintTbigintLogicalFunction::AddBigintTbigintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType AddBigintTbigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AddBigintTbigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AddBigintTbigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AddBigintTbigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AddBigintTbigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AddBigintTbigintLogicalFunction::getType() const { return NAME; } + +bool AddBigintTbigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AddBigintTbigintLogicalFunction::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 AddBigintTbigintLogicalFunction::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 AddBigintTbigintLogicalFunction::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::RegisterAddBigintTbigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AddBigintTbigintLogicalFunction 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 AddBigintTbigintLogicalFunction(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 b183f783d5..a99de0cdb4 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -26,6 +26,7 @@ add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogi add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) add_plugin(AddFloatTfloat LogicalFunction nes-logical-operators AddFloatTfloatLogicalFunction.cpp) add_plugin(AddTfloatFloat LogicalFunction nes-logical-operators AddTfloatFloatLogicalFunction.cpp) +add_plugin(AddBigintTbigint LogicalFunction nes-logical-operators AddBigintTbigintLogicalFunction.cpp) add_plugin(AddTbigintBigint LogicalFunction nes-logical-operators AddTbigintBigintLogicalFunction.cpp) add_plugin(AddIntTint LogicalFunction nes-logical-operators AddIntTintLogicalFunction.cpp) add_plugin(AddTintInt LogicalFunction nes-logical-operators AddTintIntLogicalFunction.cpp) @@ -37,14 +38,17 @@ add_plugin(TemporalRound LogicalFunction nes-logical-operators TemporalRoundLogi 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(DivBigintTbigint LogicalFunction nes-logical-operators DivBigintTbigintLogicalFunction.cpp) add_plugin(DivTbigintBigint LogicalFunction nes-logical-operators DivTbigintBigintLogicalFunction.cpp) add_plugin(DivIntTint LogicalFunction nes-logical-operators DivIntTintLogicalFunction.cpp) add_plugin(DivTintInt LogicalFunction nes-logical-operators DivTintIntLogicalFunction.cpp) add_plugin(DivTnumberTnumber LogicalFunction nes-logical-operators DivTnumberTnumberLogicalFunction.cpp) +add_plugin(MulBigintTbigint LogicalFunction nes-logical-operators MulBigintTbigintLogicalFunction.cpp) add_plugin(MulTbigintBigint LogicalFunction nes-logical-operators MulTbigintBigintLogicalFunction.cpp) add_plugin(MulIntTint LogicalFunction nes-logical-operators MulIntTintLogicalFunction.cpp) add_plugin(MulTintInt LogicalFunction nes-logical-operators MulTintIntLogicalFunction.cpp) add_plugin(MulTnumberTnumber LogicalFunction nes-logical-operators MulTnumberTnumberLogicalFunction.cpp) +add_plugin(SubBigintTbigint LogicalFunction nes-logical-operators SubBigintTbigintLogicalFunction.cpp) add_plugin(SubTbigintBigint LogicalFunction nes-logical-operators SubTbigintBigintLogicalFunction.cpp) add_plugin(SubIntTint LogicalFunction nes-logical-operators SubIntTintLogicalFunction.cpp) add_plugin(SubTintInt LogicalFunction nes-logical-operators SubTintIntLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/DivBigintTbigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/DivBigintTbigintLogicalFunction.cpp new file mode 100644 index 0000000000..166a3c2100 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/DivBigintTbigintLogicalFunction.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 +{ + +DivBigintTbigintLogicalFunction::DivBigintTbigintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType DivBigintTbigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction DivBigintTbigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector DivBigintTbigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction DivBigintTbigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "DivBigintTbigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view DivBigintTbigintLogicalFunction::getType() const { return NAME; } + +bool DivBigintTbigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string DivBigintTbigintLogicalFunction::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 DivBigintTbigintLogicalFunction::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 DivBigintTbigintLogicalFunction::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::RegisterDivBigintTbigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "DivBigintTbigintLogicalFunction 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 DivBigintTbigintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/MulBigintTbigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/MulBigintTbigintLogicalFunction.cpp new file mode 100644 index 0000000000..97c43c36c7 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/MulBigintTbigintLogicalFunction.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 +{ + +MulBigintTbigintLogicalFunction::MulBigintTbigintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType MulBigintTbigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction MulBigintTbigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector MulBigintTbigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction MulBigintTbigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "MulBigintTbigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view MulBigintTbigintLogicalFunction::getType() const { return NAME; } + +bool MulBigintTbigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string MulBigintTbigintLogicalFunction::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 MulBigintTbigintLogicalFunction::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 MulBigintTbigintLogicalFunction::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::RegisterMulBigintTbigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "MulBigintTbigintLogicalFunction 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 MulBigintTbigintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/SubBigintTbigintLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/SubBigintTbigintLogicalFunction.cpp new file mode 100644 index 0000000000..1d28d41eeb --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/SubBigintTbigintLogicalFunction.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 +{ + +SubBigintTbigintLogicalFunction::SubBigintTbigintLogicalFunction(LogicalFunction scalar, + LogicalFunction value, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(scalar)); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(ts)); +} + +DataType SubBigintTbigintLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction SubBigintTbigintLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector SubBigintTbigintLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction SubBigintTbigintLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "SubBigintTbigintLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view SubBigintTbigintLogicalFunction::getType() const { return NAME; } + +bool SubBigintTbigintLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string SubBigintTbigintLogicalFunction::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 SubBigintTbigintLogicalFunction::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 SubBigintTbigintLogicalFunction::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::RegisterSubBigintTbigintLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "SubBigintTbigintLogicalFunction 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 SubBigintTbigintLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/AddBigintTbigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AddBigintTbigintPhysicalFunction.hpp new file mode 100644 index 0000000000..002afad790 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AddBigintTbigintPhysicalFunction.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_bigint_tbigint`. + * + * Per-event add_bigint_tbigint: adds a constant int64 scalar to a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AddBigintTbigintPhysicalFunction : public PhysicalFunctionConcept { +public: + AddBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + 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/DivBigintTbigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/DivBigintTbigintPhysicalFunction.hpp new file mode 100644 index 0000000000..388ea20550 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/DivBigintTbigintPhysicalFunction.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_bigint_tbigint`. + * + * Per-event div_bigint_tbigint: divides a constant int64 scalar by a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class DivBigintTbigintPhysicalFunction : public PhysicalFunctionConcept { +public: + DivBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + 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/MulBigintTbigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/MulBigintTbigintPhysicalFunction.hpp new file mode 100644 index 0000000000..8e83307019 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/MulBigintTbigintPhysicalFunction.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_bigint_tbigint`. + * + * Per-event mul_bigint_tbigint: multiplies a constant int64 scalar by a single-instant tbigint value. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class MulBigintTbigintPhysicalFunction : public PhysicalFunctionConcept { +public: + MulBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + 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/SubBigintTbigintPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/SubBigintTbigintPhysicalFunction.hpp new file mode 100644 index 0000000000..3c3558ab49 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/SubBigintTbigintPhysicalFunction.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_bigint_tbigint`. + * + * Per-event sub_bigint_tbigint: subtracts a single-instant tbigint value from a constant int64 scalar. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class SubBigintTbigintPhysicalFunction : public PhysicalFunctionConcept { +public: + SubBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + 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/AddBigintTbigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AddBigintTbigintPhysicalFunction.cpp new file mode 100644 index 0000000000..524b303ad8 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AddBigintTbigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +AddBigintTbigintPhysicalFunction::AddBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AddBigintTbigintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), + MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = add_bigint_tbigint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAddBigintTbigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AddBigintTbigintPhysicalFunction 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 AddBigintTbigintPhysicalFunction(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 d6ede70801..036d4bdf7d 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -25,6 +25,7 @@ add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPh add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) add_plugin(AddFloatTfloat PhysicalFunction nes-physical-operators AddFloatTfloatPhysicalFunction.cpp) add_plugin(AddTfloatFloat PhysicalFunction nes-physical-operators AddTfloatFloatPhysicalFunction.cpp) +add_plugin(AddBigintTbigint PhysicalFunction nes-physical-operators AddBigintTbigintPhysicalFunction.cpp) add_plugin(AddTbigintBigint PhysicalFunction nes-physical-operators AddTbigintBigintPhysicalFunction.cpp) add_plugin(AddIntTint PhysicalFunction nes-physical-operators AddIntTintPhysicalFunction.cpp) add_plugin(AddTintInt PhysicalFunction nes-physical-operators AddTintIntPhysicalFunction.cpp) @@ -36,14 +37,17 @@ add_plugin(TemporalRound PhysicalFunction nes-physical-operators TemporalRoundPh 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(DivBigintTbigint PhysicalFunction nes-physical-operators DivBigintTbigintPhysicalFunction.cpp) add_plugin(DivTbigintBigint PhysicalFunction nes-physical-operators DivTbigintBigintPhysicalFunction.cpp) add_plugin(DivIntTint PhysicalFunction nes-physical-operators DivIntTintPhysicalFunction.cpp) add_plugin(DivTintInt PhysicalFunction nes-physical-operators DivTintIntPhysicalFunction.cpp) add_plugin(DivTnumberTnumber PhysicalFunction nes-physical-operators DivTnumberTnumberPhysicalFunction.cpp) +add_plugin(MulBigintTbigint PhysicalFunction nes-physical-operators MulBigintTbigintPhysicalFunction.cpp) add_plugin(MulTbigintBigint PhysicalFunction nes-physical-operators MulTbigintBigintPhysicalFunction.cpp) add_plugin(MulIntTint PhysicalFunction nes-physical-operators MulIntTintPhysicalFunction.cpp) add_plugin(MulTintInt PhysicalFunction nes-physical-operators MulTintIntPhysicalFunction.cpp) add_plugin(MulTnumberTnumber PhysicalFunction nes-physical-operators MulTnumberTnumberPhysicalFunction.cpp) +add_plugin(SubBigintTbigint PhysicalFunction nes-physical-operators SubBigintTbigintPhysicalFunction.cpp) add_plugin(SubTbigintBigint PhysicalFunction nes-physical-operators SubTbigintBigintPhysicalFunction.cpp) add_plugin(SubIntTint PhysicalFunction nes-physical-operators SubIntTintPhysicalFunction.cpp) add_plugin(SubTintInt PhysicalFunction nes-physical-operators SubTintIntPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/DivBigintTbigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/DivBigintTbigintPhysicalFunction.cpp new file mode 100644 index 0000000000..5d79d2132b --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/DivBigintTbigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +DivBigintTbigintPhysicalFunction::DivBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal DivBigintTbigintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), + MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = div_bigint_tbigint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterDivBigintTbigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "DivBigintTbigintPhysicalFunction 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 DivBigintTbigintPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/MulBigintTbigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/MulBigintTbigintPhysicalFunction.cpp new file mode 100644 index 0000000000..0919846d1d --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/MulBigintTbigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +MulBigintTbigintPhysicalFunction::MulBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal MulBigintTbigintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), + MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = mul_bigint_tbigint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterMulBigintTbigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "MulBigintTbigintPhysicalFunction 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 MulBigintTbigintPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/SubBigintTbigintPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/SubBigintTbigintPhysicalFunction.cpp new file mode 100644 index 0000000000..a6331aec84 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/SubBigintTbigintPhysicalFunction.cpp @@ -0,0 +1,92 @@ +/* + 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 { + +SubBigintTbigintPhysicalFunction::SubBigintTbigintPhysicalFunction(PhysicalFunction scalarFunction, + PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(scalarFunction)); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal SubBigintTbigintPhysicalFunction::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 scalar = parameterValues[0].cast>(); + auto value = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double scalar_d, double value_d, uint64_t ts) -> double { + try { + MEOS::Meos::ensureMeosInitialized(); + std::string tempWkt = fmt::format("{}@{}", static_cast(value_d), + MEOS::Meos::convertEpochToTimestamp(ts)); + Temporal* temp = tbigint_in(tempWkt.c_str()); + if (!temp) return 0.0; + Temporal* res = sub_bigint_tbigint(static_cast(scalar_d), 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; } + }, + scalar, value, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterSubBigintTbigintPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "SubBigintTbigintPhysicalFunction 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 SubBigintTbigintPhysicalFunction(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 e38329c1d3..b65b957e47 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_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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; +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_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -488,24 +488,28 @@ 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_BIGINT_TBIGINT: 'ADD_BIGINT_TBIGINT' | 'add_bigint_tbigint'; ADD_FLOAT_TFLOAT: 'ADD_FLOAT_TFLOAT' | 'add_float_tfloat'; ADD_TBIGINT_BIGINT: 'ADD_TBIGINT_BIGINT' | 'add_tbigint_bigint'; ADD_TFLOAT_FLOAT: 'ADD_TFLOAT_FLOAT' | 'add_tfloat_float'; ADD_INT_TINT: 'ADD_INT_TINT' | 'add_int_tint'; ADD_TINT_INT: 'ADD_TINT_INT' | 'add_tint_int'; ADD_TNUMBER_TNUMBER: 'ADD_TNUMBER_TNUMBER' | 'add_tnumber_tnumber'; +DIV_BIGINT_TBIGINT: 'DIV_BIGINT_TBIGINT' | 'div_bigint_tbigint'; DIV_FLOAT_TFLOAT: 'DIV_FLOAT_TFLOAT' | 'div_float_tfloat'; DIV_TBIGINT_BIGINT: 'DIV_TBIGINT_BIGINT' | 'div_tbigint_bigint'; DIV_TFLOAT_FLOAT: 'DIV_TFLOAT_FLOAT' | 'div_tfloat_float'; DIV_INT_TINT: 'DIV_INT_TINT' | 'div_int_tint'; DIV_TINT_INT: 'DIV_TINT_INT' | 'div_tint_int'; DIV_TNUMBER_TNUMBER: 'DIV_TNUMBER_TNUMBER' | 'div_tnumber_tnumber'; +MUL_BIGINT_TBIGINT: 'MUL_BIGINT_TBIGINT' | 'mul_bigint_tbigint'; MUL_FLOAT_TFLOAT: 'MUL_FLOAT_TFLOAT' | 'mul_float_tfloat'; MUL_TBIGINT_BIGINT: 'MUL_TBIGINT_BIGINT' | 'mul_tbigint_bigint'; MUL_TFLOAT_FLOAT: 'MUL_TFLOAT_FLOAT' | 'mul_tfloat_float'; MUL_INT_TINT: 'MUL_INT_TINT' | 'mul_int_tint'; MUL_TINT_INT: 'MUL_TINT_INT' | 'mul_tint_int'; MUL_TNUMBER_TNUMBER: 'MUL_TNUMBER_TNUMBER' | 'mul_tnumber_tnumber'; +SUB_BIGINT_TBIGINT: 'SUB_BIGINT_TBIGINT' | 'sub_bigint_tbigint'; SUB_FLOAT_TFLOAT: 'SUB_FLOAT_TFLOAT' | 'sub_float_tfloat'; SUB_TBIGINT_BIGINT: 'SUB_TBIGINT_BIGINT' | 'sub_tbigint_bigint'; SUB_TFLOAT_FLOAT: 'SUB_TFLOAT_FLOAT' | 'sub_tfloat_float'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index c7666a5cdc..f14eea84b1 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -69,24 +69,28 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -1838,6 +1842,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: SUB_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ADD_BIGINT_TBIGINT */ + case AntlrSQLLexer::ADD_BIGINT_TBIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ADD_BIGINT_TBIGINT 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(AddBigintTbigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ADD_BIGINT_TBIGINT */ /* BEGIN CODEGEN PARSER GLUE: ADD_TBIGINT_BIGINT */ case AntlrSQLLexer::ADD_TBIGINT_BIGINT: { @@ -1925,6 +1958,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: ADD_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: DIV_BIGINT_TBIGINT */ + case AntlrSQLLexer::DIV_BIGINT_TBIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("DIV_BIGINT_TBIGINT 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(DivBigintTbigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: DIV_BIGINT_TBIGINT */ /* BEGIN CODEGEN PARSER GLUE: DIV_TBIGINT_BIGINT */ case AntlrSQLLexer::DIV_TBIGINT_BIGINT: { @@ -2012,6 +2074,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: DIV_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: MUL_BIGINT_TBIGINT */ + case AntlrSQLLexer::MUL_BIGINT_TBIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("MUL_BIGINT_TBIGINT 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(MulBigintTbigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: MUL_BIGINT_TBIGINT */ /* BEGIN CODEGEN PARSER GLUE: MUL_TBIGINT_BIGINT */ case AntlrSQLLexer::MUL_TBIGINT_BIGINT: { @@ -2099,6 +2190,35 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: MUL_TINT_INT */ + /* BEGIN CODEGEN PARSER GLUE: SUB_BIGINT_TBIGINT */ + case AntlrSQLLexer::SUB_BIGINT_TBIGINT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("SUB_BIGINT_TBIGINT 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(SubBigintTbigintLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: SUB_BIGINT_TBIGINT */ /* BEGIN CODEGEN PARSER GLUE: SUB_TBIGINT_BIGINT */ case AntlrSQLLexer::SUB_TBIGINT_BIGINT: { From 5d3a3c92e6860f667f8b2977c57ab73172493fbb Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 08:34:22 +0200 Subject: [PATCH 18/20] feat(meos): add TFLOAT_EXP, TFLOAT_LN, TFLOAT_LOG10 NES operators (W60) Adds per-event scalar NES operators for exponential and logarithmic functions on tfloat temporals: TFLOAT_EXP, TFLOAT_LN, TFLOAT_LOG10. Each operator takes (value:float, ts:uint64) and delegates to the corresponding MEOS tfloat_exp / tfloat_ln / tfloat_log10 kernel. --- .../Meos/TfloatExpLogicalFunction.hpp | 53 +++++++++ .../Meos/TfloatLnLogicalFunction.hpp | 53 +++++++++ .../Meos/TfloatLog10LogicalFunction.hpp | 53 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../Meos/TfloatExpLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatLnLogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatLog10LogicalFunction.cpp | 102 ++++++++++++++++++ .../Meos/TfloatExpPhysicalFunction.hpp | 42 ++++++++ .../Meos/TfloatLnPhysicalFunction.hpp | 42 ++++++++ .../Meos/TfloatLog10PhysicalFunction.hpp | 42 ++++++++ .../src/Functions/Meos/CMakeLists.txt | 3 + .../Meos/TfloatExpPhysicalFunction.cpp | 87 +++++++++++++++ .../Meos/TfloatLnPhysicalFunction.cpp | 87 +++++++++++++++ .../Meos/TfloatLog10PhysicalFunction.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/TfloatExpLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatLnLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/TfloatLog10LogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatExpLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatLnLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/TfloatLog10LogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatExpPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatLnPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/TfloatLog10PhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatExpPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatLnPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/TfloatLog10PhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/TfloatExpLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatExpLogicalFunction.hpp new file mode 100644 index 0000000000..a006015a7b --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatExpLogicalFunction.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_exp: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_exp`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatExpLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatExp"; + + TfloatExpLogicalFunction(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/TfloatLnLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatLnLogicalFunction.hpp new file mode 100644 index 0000000000..2924cce5ff --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatLnLogicalFunction.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_ln: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_ln`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatLnLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatLn"; + + TfloatLnLogicalFunction(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/TfloatLog10LogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/TfloatLog10LogicalFunction.hpp new file mode 100644 index 0000000000..0b3703d878 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/TfloatLog10LogicalFunction.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_log10: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `tfloat_log10`. Per-event scalar operator following the + * TemporalEDWithinGeometry pattern. + */ +class TfloatLog10LogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "TfloatLog10"; + + TfloatLog10LogicalFunction(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 a99de0cdb4..269767f962 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -21,7 +21,10 @@ add_plugin(TemporalAtStBox LogicalFunction nes-logical-operators TemporalAtStBox 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(TfloatExp LogicalFunction nes-logical-operators TfloatExpLogicalFunction.cpp) add_plugin(TfloatFloor LogicalFunction nes-logical-operators TfloatFloorLogicalFunction.cpp) +add_plugin(TfloatLn LogicalFunction nes-logical-operators TfloatLnLogicalFunction.cpp) +add_plugin(TfloatLog10 LogicalFunction nes-logical-operators TfloatLog10LogicalFunction.cpp) add_plugin(TfloatRadians LogicalFunction nes-logical-operators TfloatRadiansLogicalFunction.cpp) add_plugin(TfloatScaleValue LogicalFunction nes-logical-operators TfloatScaleValueLogicalFunction.cpp) add_plugin(AddFloatTfloat LogicalFunction nes-logical-operators AddFloatTfloatLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/TfloatExpLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatExpLogicalFunction.cpp new file mode 100644 index 0000000000..bf6a97e365 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatExpLogicalFunction.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 +{ + +TfloatExpLogicalFunction::TfloatExpLogicalFunction(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 TfloatExpLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatExpLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatExpLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatExpLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatExpLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatExpLogicalFunction::getType() const { return NAME; } + +bool TfloatExpLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatExpLogicalFunction::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 TfloatExpLogicalFunction::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 TfloatExpLogicalFunction::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::RegisterTfloatExpLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatExpLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatExpLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatLnLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatLnLogicalFunction.cpp new file mode 100644 index 0000000000..2d12b9baa5 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatLnLogicalFunction.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 +{ + +TfloatLnLogicalFunction::TfloatLnLogicalFunction(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 TfloatLnLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatLnLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatLnLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatLnLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatLnLogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatLnLogicalFunction::getType() const { return NAME; } + +bool TfloatLnLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatLnLogicalFunction::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 TfloatLnLogicalFunction::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 TfloatLnLogicalFunction::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::RegisterTfloatLnLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatLnLogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatLnLogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/TfloatLog10LogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/TfloatLog10LogicalFunction.cpp new file mode 100644 index 0000000000..22fe17e9ba --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/TfloatLog10LogicalFunction.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 +{ + +TfloatLog10LogicalFunction::TfloatLog10LogicalFunction(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 TfloatLog10LogicalFunction::getDataType() const { return dataType; } + +LogicalFunction TfloatLog10LogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector TfloatLog10LogicalFunction::getChildren() const { return parameters; } + +LogicalFunction TfloatLog10LogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 2, "TfloatLog10LogicalFunction requires 2 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view TfloatLog10LogicalFunction::getType() const { return NAME; } + +bool TfloatLog10LogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string TfloatLog10LogicalFunction::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 TfloatLog10LogicalFunction::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 TfloatLog10LogicalFunction::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::RegisterTfloatLog10LogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 2, + "TfloatLog10LogicalFunction requires 2 children but got {}", + arguments.children.size()); + auto arg0 = std::move(arguments.children[0]); + auto arg1 = std::move(arguments.children[1]); + return TfloatLog10LogicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/TfloatExpPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatExpPhysicalFunction.hpp new file mode 100644 index 0000000000..3f4c0e84be --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatExpPhysicalFunction.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_exp`. + * + * Per-event tfloat_exp: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatExpPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatExpPhysicalFunction(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/TfloatLnPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatLnPhysicalFunction.hpp new file mode 100644 index 0000000000..e2539cd8f5 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatLnPhysicalFunction.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_ln`. + * + * Per-event tfloat_ln: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatLnPhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatLnPhysicalFunction(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/TfloatLog10PhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/TfloatLog10PhysicalFunction.hpp new file mode 100644 index 0000000000..47439e84e8 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/TfloatLog10PhysicalFunction.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_log10`. + * + * Per-event tfloat_log10: single-instant tfloat transform, value extracted -> double. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class TfloatLog10PhysicalFunction : public PhysicalFunctionConcept { +public: + TfloatLog10PhysicalFunction(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 036d4bdf7d..36c772b8d9 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -20,7 +20,10 @@ add_plugin(TemporalAtStBox PhysicalFunction nes-physical-operators TemporalAtStB 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(TfloatExp PhysicalFunction nes-physical-operators TfloatExpPhysicalFunction.cpp) add_plugin(TfloatFloor PhysicalFunction nes-physical-operators TfloatFloorPhysicalFunction.cpp) +add_plugin(TfloatLn PhysicalFunction nes-physical-operators TfloatLnPhysicalFunction.cpp) +add_plugin(TfloatLog10 PhysicalFunction nes-physical-operators TfloatLog10PhysicalFunction.cpp) add_plugin(TfloatRadians PhysicalFunction nes-physical-operators TfloatRadiansPhysicalFunction.cpp) add_plugin(TfloatScaleValue PhysicalFunction nes-physical-operators TfloatScaleValuePhysicalFunction.cpp) add_plugin(AddFloatTfloat PhysicalFunction nes-physical-operators AddFloatTfloatPhysicalFunction.cpp) diff --git a/nes-physical-operators/src/Functions/Meos/TfloatExpPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatExpPhysicalFunction.cpp new file mode 100644 index 0000000000..be30a495cc --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatExpPhysicalFunction.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 { + +TfloatExpPhysicalFunction::TfloatExpPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatExpPhysicalFunction::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_exp(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::RegisterTfloatExpPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatExpPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatExpPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatLnPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatLnPhysicalFunction.cpp new file mode 100644 index 0000000000..78550610c8 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatLnPhysicalFunction.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 { + +TfloatLnPhysicalFunction::TfloatLnPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatLnPhysicalFunction::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_ln(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::RegisterTfloatLnPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatLnPhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatLnPhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/TfloatLog10PhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/TfloatLog10PhysicalFunction.cpp new file mode 100644 index 0000000000..59fba49cc9 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/TfloatLog10PhysicalFunction.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 { + +TfloatLog10PhysicalFunction::TfloatLog10PhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(2); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal TfloatLog10PhysicalFunction::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_log10(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::RegisterTfloatLog10PhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 2, + "TfloatLog10PhysicalFunction requires 2 children but got {}", + arguments.childFunctions.size()); + auto arg0 = std::move(arguments.childFunctions[0]); + auto arg1 = std::move(arguments.childFunctions[1]); + return TfloatLog10PhysicalFunction(std::move(arg0), std::move(arg1)); +} + +} // namespace NES diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index b65b957e47..141cb35cf1 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_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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; +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_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_EXP | TFLOAT_FLOOR | TFLOAT_LN | TFLOAT_LOG10 | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TBIGINT_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -528,7 +528,10 @@ TEMPORAL_ROUND: 'TEMPORAL_ROUND' | 'temporal_round'; TFLOAT_CEIL: 'TFLOAT_CEIL' | 'tfloat_ceil'; TFLOAT_COS: 'TFLOAT_COS' | 'tfloat_cos'; TFLOAT_DEGREES: 'TFLOAT_DEGREES' | 'tfloat_degrees'; +TFLOAT_EXP: 'TFLOAT_EXP' | 'tfloat_exp'; TFLOAT_FLOOR: 'TFLOAT_FLOOR' | 'tfloat_floor'; +TFLOAT_LN: 'TFLOAT_LN' | 'tfloat_ln'; +TFLOAT_LOG10: 'TFLOAT_LOG10' | 'tfloat_log10'; 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'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index f14eea84b1..e5d23de442 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -109,7 +109,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -1438,6 +1441,34 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_DEGREES */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_EXP */ + case AntlrSQLLexer::TFLOAT_EXP: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_EXP 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(TfloatExpLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_EXP */ /* BEGIN CODEGEN PARSER GLUE: TFLOAT_FLOOR */ case AntlrSQLLexer::TFLOAT_FLOOR: { @@ -1466,6 +1497,62 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TFLOAT_FLOOR */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_LN */ + case AntlrSQLLexer::TFLOAT_LN: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_LN 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(TfloatLnLogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_LN */ + /* BEGIN CODEGEN PARSER GLUE: TFLOAT_LOG10 */ + case AntlrSQLLexer::TFLOAT_LOG10: + { + const auto argCount = context->expression().size(); + if (argCount != 2) + throw InvalidQuerySyntax("TFLOAT_LOG10 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(TfloatLog10LogicalFunction(a0, a1)); + } + break; + /* END CODEGEN PARSER GLUE: TFLOAT_LOG10 */ /* BEGIN CODEGEN PARSER GLUE: TFLOAT_RADIANS */ case AntlrSQLLexer::TFLOAT_RADIANS: { From 367ebadf9c23316f0775f373d3f76739a976b29c Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 08:43:23 +0200 Subject: [PATCH 19/20] feat(meos): add EVER_EQ/GE/GT/LE/LT/NE_TFLOAT_FLOAT NES operators (W61) Adds six per-event ever-comparison scalar operators for tfloat against a float threshold: EVER_EQ_TFLOAT_FLOAT, EVER_GE_TFLOAT_FLOAT, EVER_GT_TFLOAT_FLOAT, EVER_LE_TFLOAT_FLOAT, EVER_LT_TFLOAT_FLOAT, EVER_NE_TFLOAT_FLOAT. Each operator constructs a single-instant tfloat from (value, ts), calls the corresponding MEOS ever_*_tfloat_float kernel returning int, and emits the result as double. Logical and physical function pairs, CMakeLists plugin registrations, AntlrSQL grammar tokens, and AntlrSQLQueryPlanCreator case blocks are included. --- .../Meos/EverEqTfloatFloatLogicalFunction.hpp | 54 ++++++ .../Meos/EverGeTfloatFloatLogicalFunction.hpp | 54 ++++++ .../Meos/EverGtTfloatFloatLogicalFunction.hpp | 54 ++++++ .../Meos/EverLeTfloatFloatLogicalFunction.hpp | 54 ++++++ .../Meos/EverLtTfloatFloatLogicalFunction.hpp | 54 ++++++ .../Meos/EverNeTfloatFloatLogicalFunction.hpp | 54 ++++++ .../src/Functions/Meos/CMakeLists.txt | 6 + .../Meos/EverEqTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../Meos/EverGeTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../Meos/EverGtTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../Meos/EverLeTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../Meos/EverLtTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../Meos/EverNeTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../EverEqTfloatFloatPhysicalFunction.hpp | 43 +++++ .../EverGeTfloatFloatPhysicalFunction.hpp | 43 +++++ .../EverGtTfloatFloatPhysicalFunction.hpp | 43 +++++ .../EverLeTfloatFloatPhysicalFunction.hpp | 43 +++++ .../EverLtTfloatFloatPhysicalFunction.hpp | 43 +++++ .../EverNeTfloatFloatPhysicalFunction.hpp | 43 +++++ .../src/Functions/Meos/CMakeLists.txt | 6 + .../EverEqTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../EverGeTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../EverGtTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../EverLeTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../EverLtTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../EverNeTfloatFloatPhysicalFunction.cpp | 88 +++++++++ nes-sql-parser/AntlrSQL.g4 | 8 +- .../src/AntlrSQLQueryPlanCreator.cpp | 180 ++++++++++++++++++ 28 files changed, 1939 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/EverEqTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/EverGeTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/EverGtTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/EverLeTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/EverLtTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/EverNeTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/EverEqTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/EverGeTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/EverGtTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/EverLeTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/EverLtTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/EverNeTfloatFloatLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/EverEqTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/EverGeTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/EverGtTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/EverLeTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/EverLtTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/EverNeTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/EverEqTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/EverGeTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/EverGtTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/EverLeTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/EverLtTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/EverNeTfloatFloatPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/EverEqTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/EverEqTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..c70acdbb92 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/EverEqTfloatFloatLogicalFunction.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 ever_eq_tfloat_float: tests if a single-instant tfloat value ever equals a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `ever_eq_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class EverEqTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "EverEqTfloatFloat"; + + EverEqTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/EverGeTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/EverGeTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..22b39d8182 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/EverGeTfloatFloatLogicalFunction.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 ever_ge_tfloat_float: tests if a single-instant tfloat value is ever >= a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `ever_ge_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class EverGeTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "EverGeTfloatFloat"; + + EverGeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/EverGtTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/EverGtTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..52f96894e9 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/EverGtTfloatFloatLogicalFunction.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 ever_gt_tfloat_float: tests if a single-instant tfloat value is ever > a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `ever_gt_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class EverGtTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "EverGtTfloatFloat"; + + EverGtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/EverLeTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/EverLeTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..ac1bc8a633 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/EverLeTfloatFloatLogicalFunction.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 ever_le_tfloat_float: tests if a single-instant tfloat value is ever <= a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `ever_le_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class EverLeTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "EverLeTfloatFloat"; + + EverLeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/EverLtTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/EverLtTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..599a583fb2 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/EverLtTfloatFloatLogicalFunction.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 ever_lt_tfloat_float: tests if a single-instant tfloat value is ever < a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `ever_lt_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class EverLtTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "EverLtTfloatFloat"; + + EverLtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/EverNeTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/EverNeTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..08568d04ac --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/EverNeTfloatFloatLogicalFunction.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 ever_ne_tfloat_float: tests if a single-instant tfloat value ever differs from a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `ever_ne_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class EverNeTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "EverNeTfloatFloat"; + + EverNeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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 269767f962..0c35460553 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -76,3 +76,9 @@ add_plugin(TfloatToTint LogicalFunction nes-logical-operators TfloatToTintLogica 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) +add_plugin(EverEqTfloatFloat LogicalFunction nes-logical-operators EverEqTfloatFloatLogicalFunction.cpp) +add_plugin(EverGeTfloatFloat LogicalFunction nes-logical-operators EverGeTfloatFloatLogicalFunction.cpp) +add_plugin(EverGtTfloatFloat LogicalFunction nes-logical-operators EverGtTfloatFloatLogicalFunction.cpp) +add_plugin(EverLeTfloatFloat LogicalFunction nes-logical-operators EverLeTfloatFloatLogicalFunction.cpp) +add_plugin(EverLtTfloatFloat LogicalFunction nes-logical-operators EverLtTfloatFloatLogicalFunction.cpp) +add_plugin(EverNeTfloatFloat LogicalFunction nes-logical-operators EverNeTfloatFloatLogicalFunction.cpp) diff --git a/nes-logical-operators/src/Functions/Meos/EverEqTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/EverEqTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..58a752c660 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/EverEqTfloatFloatLogicalFunction.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 +{ + +EverEqTfloatFloatLogicalFunction::EverEqTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType EverEqTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction EverEqTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector EverEqTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction EverEqTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "EverEqTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view EverEqTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool EverEqTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string EverEqTfloatFloatLogicalFunction::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 EverEqTfloatFloatLogicalFunction::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 EverEqTfloatFloatLogicalFunction::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::RegisterEverEqTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "EverEqTfloatFloatLogicalFunction 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 EverEqTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/EverGeTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/EverGeTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..c5e65c1630 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/EverGeTfloatFloatLogicalFunction.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 +{ + +EverGeTfloatFloatLogicalFunction::EverGeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType EverGeTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction EverGeTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector EverGeTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction EverGeTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "EverGeTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view EverGeTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool EverGeTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string EverGeTfloatFloatLogicalFunction::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 EverGeTfloatFloatLogicalFunction::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 EverGeTfloatFloatLogicalFunction::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::RegisterEverGeTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "EverGeTfloatFloatLogicalFunction 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 EverGeTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/EverGtTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/EverGtTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..59d09da9f5 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/EverGtTfloatFloatLogicalFunction.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 +{ + +EverGtTfloatFloatLogicalFunction::EverGtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType EverGtTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction EverGtTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector EverGtTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction EverGtTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "EverGtTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view EverGtTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool EverGtTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string EverGtTfloatFloatLogicalFunction::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 EverGtTfloatFloatLogicalFunction::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 EverGtTfloatFloatLogicalFunction::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::RegisterEverGtTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "EverGtTfloatFloatLogicalFunction 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 EverGtTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/EverLeTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/EverLeTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..d8da3f26e7 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/EverLeTfloatFloatLogicalFunction.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 +{ + +EverLeTfloatFloatLogicalFunction::EverLeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType EverLeTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction EverLeTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector EverLeTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction EverLeTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "EverLeTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view EverLeTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool EverLeTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string EverLeTfloatFloatLogicalFunction::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 EverLeTfloatFloatLogicalFunction::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 EverLeTfloatFloatLogicalFunction::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::RegisterEverLeTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "EverLeTfloatFloatLogicalFunction 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 EverLeTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/EverLtTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/EverLtTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..4dec444034 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/EverLtTfloatFloatLogicalFunction.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 +{ + +EverLtTfloatFloatLogicalFunction::EverLtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType EverLtTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction EverLtTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector EverLtTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction EverLtTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "EverLtTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view EverLtTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool EverLtTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string EverLtTfloatFloatLogicalFunction::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 EverLtTfloatFloatLogicalFunction::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 EverLtTfloatFloatLogicalFunction::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::RegisterEverLtTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "EverLtTfloatFloatLogicalFunction 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 EverLtTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/EverNeTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/EverNeTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..5ce1fbdbb9 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/EverNeTfloatFloatLogicalFunction.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 +{ + +EverNeTfloatFloatLogicalFunction::EverNeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType EverNeTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction EverNeTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector EverNeTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction EverNeTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "EverNeTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view EverNeTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool EverNeTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string EverNeTfloatFloatLogicalFunction::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 EverNeTfloatFloatLogicalFunction::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 EverNeTfloatFloatLogicalFunction::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::RegisterEverNeTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "EverNeTfloatFloatLogicalFunction 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 EverNeTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/include/Functions/Meos/EverEqTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/EverEqTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..6a639a7d81 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/EverEqTfloatFloatPhysicalFunction.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 `ever_eq_tfloat_float`. + * + * Per-event ever_eq_tfloat_float: tests if a single-instant tfloat value ever equals a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class EverEqTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + EverEqTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/EverGeTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/EverGeTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..71be2abc10 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/EverGeTfloatFloatPhysicalFunction.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 `ever_ge_tfloat_float`. + * + * Per-event ever_ge_tfloat_float: tests if a single-instant tfloat value is ever >= a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class EverGeTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + EverGeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/EverGtTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/EverGtTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..1d16f7234f --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/EverGtTfloatFloatPhysicalFunction.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 `ever_gt_tfloat_float`. + * + * Per-event ever_gt_tfloat_float: tests if a single-instant tfloat value is ever > a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class EverGtTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + EverGtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/EverLeTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/EverLeTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..6b2c963040 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/EverLeTfloatFloatPhysicalFunction.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 `ever_le_tfloat_float`. + * + * Per-event ever_le_tfloat_float: tests if a single-instant tfloat value is ever <= a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class EverLeTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + EverLeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/EverLtTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/EverLtTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..cc393311c9 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/EverLtTfloatFloatPhysicalFunction.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 `ever_lt_tfloat_float`. + * + * Per-event ever_lt_tfloat_float: tests if a single-instant tfloat value is ever < a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class EverLtTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + EverLtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/EverNeTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/EverNeTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..61ae514722 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/EverNeTfloatFloatPhysicalFunction.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 `ever_ne_tfloat_float`. + * + * Per-event ever_ne_tfloat_float: tests if a single-instant tfloat value ever differs from a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class EverNeTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + EverNeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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 36c772b8d9..43cddd97b6 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -75,4 +75,10 @@ add_plugin(TfloatToTint PhysicalFunction nes-physical-operators TfloatToTintPhys 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) +add_plugin(EverEqTfloatFloat PhysicalFunction nes-physical-operators EverEqTfloatFloatPhysicalFunction.cpp) +add_plugin(EverGeTfloatFloat PhysicalFunction nes-physical-operators EverGeTfloatFloatPhysicalFunction.cpp) +add_plugin(EverGtTfloatFloat PhysicalFunction nes-physical-operators EverGtTfloatFloatPhysicalFunction.cpp) +add_plugin(EverLeTfloatFloat PhysicalFunction nes-physical-operators EverLeTfloatFloatPhysicalFunction.cpp) +add_plugin(EverLtTfloatFloat PhysicalFunction nes-physical-operators EverLtTfloatFloatPhysicalFunction.cpp) +add_plugin(EverNeTfloatFloat PhysicalFunction nes-physical-operators EverNeTfloatFloatPhysicalFunction.cpp) endif() diff --git a/nes-physical-operators/src/Functions/Meos/EverEqTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/EverEqTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..86aa083ad2 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/EverEqTfloatFloatPhysicalFunction.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 { + +EverEqTfloatFloatPhysicalFunction::EverEqTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal EverEqTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = ever_eq_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterEverEqTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "EverEqTfloatFloatPhysicalFunction 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 EverEqTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/EverGeTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/EverGeTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..d234284498 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/EverGeTfloatFloatPhysicalFunction.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 { + +EverGeTfloatFloatPhysicalFunction::EverGeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal EverGeTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = ever_ge_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterEverGeTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "EverGeTfloatFloatPhysicalFunction 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 EverGeTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/EverGtTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/EverGtTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..a8ba01257d --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/EverGtTfloatFloatPhysicalFunction.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 { + +EverGtTfloatFloatPhysicalFunction::EverGtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal EverGtTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = ever_gt_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterEverGtTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "EverGtTfloatFloatPhysicalFunction 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 EverGtTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/EverLeTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/EverLeTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..2724078153 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/EverLeTfloatFloatPhysicalFunction.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 { + +EverLeTfloatFloatPhysicalFunction::EverLeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal EverLeTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = ever_le_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterEverLeTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "EverLeTfloatFloatPhysicalFunction 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 EverLeTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/EverLtTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/EverLtTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..7717a654f2 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/EverLtTfloatFloatPhysicalFunction.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 { + +EverLtTfloatFloatPhysicalFunction::EverLtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal EverLtTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = ever_lt_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterEverLtTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "EverLtTfloatFloatPhysicalFunction 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 EverLtTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/EverNeTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/EverNeTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..681b87ea0e --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/EverNeTfloatFloatPhysicalFunction.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 { + +EverNeTfloatFloatPhysicalFunction::EverNeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal EverNeTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = ever_ne_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterEverNeTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "EverNeTfloatFloatPhysicalFunction 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 EverNeTfloatFloatPhysicalFunction(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 141cb35cf1..ec195f471d 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_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_EXP | TFLOAT_FLOOR | TFLOAT_LN | TFLOAT_LOG10 | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TBIGINT_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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; +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 | EVER_EQ_TFLOAT_FLOAT | EVER_GE_TFLOAT_FLOAT | EVER_GT_TFLOAT_FLOAT | EVER_LE_TFLOAT_FLOAT | EVER_LT_TFLOAT_FLOAT | EVER_NE_TFLOAT_FLOAT | TGEO_AT_STBOX | ADD_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_EXP | TFLOAT_FLOOR | TFLOAT_LN | TFLOAT_LOG10 | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TBIGINT_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -487,6 +487,12 @@ TEMPORAL_EINTERSECTS_GEOMETRY: 'TEMPORAL_EINTERSECTS_GEOMETRY' | 'temporal_einte TEMPORAL_AINTERSECTS_GEOMETRY: 'TEMPORAL_AINTERSECTS_GEOMETRY' | 'temporal_aintersects_geometry'; TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains_geometry'; EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; +EVER_EQ_TFLOAT_FLOAT: 'EVER_EQ_TFLOAT_FLOAT' | 'ever_eq_tfloat_float'; +EVER_GE_TFLOAT_FLOAT: 'EVER_GE_TFLOAT_FLOAT' | 'ever_ge_tfloat_float'; +EVER_GT_TFLOAT_FLOAT: 'EVER_GT_TFLOAT_FLOAT' | 'ever_gt_tfloat_float'; +EVER_LE_TFLOAT_FLOAT: 'EVER_LE_TFLOAT_FLOAT' | 'ever_le_tfloat_float'; +EVER_LT_TFLOAT_FLOAT: 'EVER_LT_TFLOAT_FLOAT' | 'ever_lt_tfloat_float'; +EVER_NE_TFLOAT_FLOAT: 'EVER_NE_TFLOAT_FLOAT' | 'ever_ne_tfloat_float'; TGEO_AT_STBOX: 'TGEO_AT_STBOX' | 'tgeo_at_stbox'; ADD_BIGINT_TBIGINT: 'ADD_BIGINT_TBIGINT' | 'add_bigint_tbigint'; ADD_FLOAT_TFLOAT: 'ADD_FLOAT_TFLOAT' | 'add_float_tfloat'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index e5d23de442..545ac88c27 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -127,6 +127,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -2914,6 +2920,180 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: TINT_TO_TFLOAT */ + /* BEGIN CODEGEN PARSER GLUE: EVER_EQ_TFLOAT_FLOAT */ + case AntlrSQLLexer::EVER_EQ_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("EVER_EQ_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(EverEqTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: EVER_EQ_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: EVER_GE_TFLOAT_FLOAT */ + case AntlrSQLLexer::EVER_GE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("EVER_GE_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(EverGeTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: EVER_GE_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: EVER_GT_TFLOAT_FLOAT */ + case AntlrSQLLexer::EVER_GT_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("EVER_GT_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(EverGtTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: EVER_GT_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: EVER_LE_TFLOAT_FLOAT */ + case AntlrSQLLexer::EVER_LE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("EVER_LE_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(EverLeTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: EVER_LE_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: EVER_LT_TFLOAT_FLOAT */ + case AntlrSQLLexer::EVER_LT_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("EVER_LT_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(EverLtTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: EVER_LT_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: EVER_NE_TFLOAT_FLOAT */ + case AntlrSQLLexer::EVER_NE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("EVER_NE_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(EverNeTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: EVER_NE_TFLOAT_FLOAT */ default: /// Check if the function is a constructor for a datatype From 2c9998dec9fb03bdbac655d15643b028c21b5eb9 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Fri, 12 Jun 2026 08:50:09 +0200 Subject: [PATCH 20/20] feat(meos): add ALWAYS_EQ/GE/GT/LE/LT/NE_TFLOAT_FLOAT NES operators (W62) Adds six per-event always-comparison scalar operators for tfloat against a float threshold: ALWAYS_EQ_TFLOAT_FLOAT, ALWAYS_GE_TFLOAT_FLOAT, ALWAYS_GT_TFLOAT_FLOAT, ALWAYS_LE_TFLOAT_FLOAT, ALWAYS_LT_TFLOAT_FLOAT, ALWAYS_NE_TFLOAT_FLOAT. Each operator constructs a single-instant tfloat from (value, ts), calls the corresponding MEOS always_*_tfloat_float kernel returning int, and emits the result as double. Logical and physical function pairs, CMakeLists plugin registrations, AntlrSQL grammar tokens, and AntlrSQLQueryPlanCreator case blocks are included. --- .../AlwaysEqTfloatFloatLogicalFunction.hpp | 54 ++++++ .../AlwaysGeTfloatFloatLogicalFunction.hpp | 54 ++++++ .../AlwaysGtTfloatFloatLogicalFunction.hpp | 54 ++++++ .../AlwaysLeTfloatFloatLogicalFunction.hpp | 54 ++++++ .../AlwaysLtTfloatFloatLogicalFunction.hpp | 54 ++++++ .../AlwaysNeTfloatFloatLogicalFunction.hpp | 54 ++++++ .../AlwaysEqTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../AlwaysGeTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../AlwaysGtTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../AlwaysLeTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../AlwaysLtTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../AlwaysNeTfloatFloatLogicalFunction.cpp | 105 ++++++++++ .../src/Functions/Meos/CMakeLists.txt | 6 + .../AlwaysEqTfloatFloatPhysicalFunction.hpp | 43 +++++ .../AlwaysGeTfloatFloatPhysicalFunction.hpp | 43 +++++ .../AlwaysGtTfloatFloatPhysicalFunction.hpp | 43 +++++ .../AlwaysLeTfloatFloatPhysicalFunction.hpp | 43 +++++ .../AlwaysLtTfloatFloatPhysicalFunction.hpp | 43 +++++ .../AlwaysNeTfloatFloatPhysicalFunction.hpp | 43 +++++ .../AlwaysEqTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../AlwaysGeTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../AlwaysGtTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../AlwaysLeTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../AlwaysLtTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../AlwaysNeTfloatFloatPhysicalFunction.cpp | 88 +++++++++ .../src/Functions/Meos/CMakeLists.txt | 6 + nes-sql-parser/AntlrSQL.g4 | 8 +- .../src/AntlrSQLQueryPlanCreator.cpp | 180 ++++++++++++++++++ 28 files changed, 1939 insertions(+), 1 deletion(-) create mode 100644 nes-logical-operators/include/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/include/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.hpp create mode 100644 nes-logical-operators/src/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.cpp create mode 100644 nes-logical-operators/src/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.cpp create mode 100644 nes-physical-operators/include/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/include/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.hpp create mode 100644 nes-physical-operators/src/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.cpp create mode 100644 nes-physical-operators/src/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.cpp diff --git a/nes-logical-operators/include/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..4feb84d46e --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.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 always_eq_tfloat_float: tests if a single-instant tfloat value always equals a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `always_eq_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class AlwaysEqTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AlwaysEqTfloatFloat"; + + AlwaysEqTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/AlwaysGeTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..a7ef047a6b --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.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 always_ge_tfloat_float: tests if a single-instant tfloat value always is greater than or equal to a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `always_ge_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class AlwaysGeTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AlwaysGeTfloatFloat"; + + AlwaysGeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/AlwaysGtTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..f85e4558e1 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.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 always_gt_tfloat_float: tests if a single-instant tfloat value always is greater than a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `always_gt_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class AlwaysGtTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AlwaysGtTfloatFloat"; + + AlwaysGtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/AlwaysLeTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..1ce49d77a7 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.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 always_le_tfloat_float: tests if a single-instant tfloat value always is less than or equal to a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `always_le_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class AlwaysLeTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AlwaysLeTfloatFloat"; + + AlwaysLeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/AlwaysLtTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..fbf9801378 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.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 always_lt_tfloat_float: tests if a single-instant tfloat value always is less than a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `always_lt_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class AlwaysLtTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AlwaysLtTfloatFloat"; + + AlwaysLtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/AlwaysNeTfloatFloatLogicalFunction.hpp b/nes-logical-operators/include/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.hpp new file mode 100644 index 0000000000..7a80868519 --- /dev/null +++ b/nes-logical-operators/include/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.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 always_ne_tfloat_float: tests if a single-instant tfloat value always is not equal to a threshold. + * + * Generated by tools/codegen/codegen_nebula.py from the MEOS function + * `always_ne_tfloat_float`. Takes (value:FLOAT64, threshold:FLOAT64, ts:UINT64), + * constructs a single-instant temporal, applies the comparison, and returns FLOAT64 (0.0/1.0). + */ +class AlwaysNeTfloatFloatLogicalFunction : public LogicalFunctionConcept { +public: + static constexpr std::string_view NAME = "AlwaysNeTfloatFloat"; + + AlwaysNeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + 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/AlwaysEqTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..d7a01dae71 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AlwaysEqTfloatFloatLogicalFunction.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 +{ + +AlwaysEqTfloatFloatLogicalFunction::AlwaysEqTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType AlwaysEqTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AlwaysEqTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AlwaysEqTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AlwaysEqTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AlwaysEqTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AlwaysEqTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AlwaysEqTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AlwaysEqTfloatFloatLogicalFunction::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 AlwaysEqTfloatFloatLogicalFunction::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 AlwaysEqTfloatFloatLogicalFunction::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::RegisterAlwaysEqTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AlwaysEqTfloatFloatLogicalFunction 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 AlwaysEqTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..712d202b14 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AlwaysGeTfloatFloatLogicalFunction.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 +{ + +AlwaysGeTfloatFloatLogicalFunction::AlwaysGeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType AlwaysGeTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AlwaysGeTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AlwaysGeTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AlwaysGeTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AlwaysGeTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AlwaysGeTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AlwaysGeTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AlwaysGeTfloatFloatLogicalFunction::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 AlwaysGeTfloatFloatLogicalFunction::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 AlwaysGeTfloatFloatLogicalFunction::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::RegisterAlwaysGeTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AlwaysGeTfloatFloatLogicalFunction 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 AlwaysGeTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..8edb267dca --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AlwaysGtTfloatFloatLogicalFunction.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 +{ + +AlwaysGtTfloatFloatLogicalFunction::AlwaysGtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType AlwaysGtTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AlwaysGtTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AlwaysGtTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AlwaysGtTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AlwaysGtTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AlwaysGtTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AlwaysGtTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AlwaysGtTfloatFloatLogicalFunction::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 AlwaysGtTfloatFloatLogicalFunction::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 AlwaysGtTfloatFloatLogicalFunction::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::RegisterAlwaysGtTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AlwaysGtTfloatFloatLogicalFunction 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 AlwaysGtTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..95d2c44151 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AlwaysLeTfloatFloatLogicalFunction.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 +{ + +AlwaysLeTfloatFloatLogicalFunction::AlwaysLeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType AlwaysLeTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AlwaysLeTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AlwaysLeTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AlwaysLeTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AlwaysLeTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AlwaysLeTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AlwaysLeTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AlwaysLeTfloatFloatLogicalFunction::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 AlwaysLeTfloatFloatLogicalFunction::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 AlwaysLeTfloatFloatLogicalFunction::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::RegisterAlwaysLeTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AlwaysLeTfloatFloatLogicalFunction 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 AlwaysLeTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..44fedc6124 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AlwaysLtTfloatFloatLogicalFunction.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 +{ + +AlwaysLtTfloatFloatLogicalFunction::AlwaysLtTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType AlwaysLtTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AlwaysLtTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AlwaysLtTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AlwaysLtTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AlwaysLtTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AlwaysLtTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AlwaysLtTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AlwaysLtTfloatFloatLogicalFunction::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 AlwaysLtTfloatFloatLogicalFunction::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 AlwaysLtTfloatFloatLogicalFunction::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::RegisterAlwaysLtTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AlwaysLtTfloatFloatLogicalFunction 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 AlwaysLtTfloatFloatLogicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-logical-operators/src/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.cpp b/nes-logical-operators/src/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.cpp new file mode 100644 index 0000000000..fab1dbb741 --- /dev/null +++ b/nes-logical-operators/src/Functions/Meos/AlwaysNeTfloatFloatLogicalFunction.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 +{ + +AlwaysNeTfloatFloatLogicalFunction::AlwaysNeTfloatFloatLogicalFunction(LogicalFunction value, + LogicalFunction threshold, + LogicalFunction ts) + : dataType(DataTypeProvider::provideDataType(DataType::Type::FLOAT64)) +{ + parameters.reserve(3); + parameters.push_back(std::move(value)); + parameters.push_back(std::move(threshold)); + parameters.push_back(std::move(ts)); +} + +DataType AlwaysNeTfloatFloatLogicalFunction::getDataType() const { return dataType; } + +LogicalFunction AlwaysNeTfloatFloatLogicalFunction::withDataType(const DataType& newDataType) const +{ + auto copy = *this; copy.dataType = newDataType; return copy; +} + +std::vector AlwaysNeTfloatFloatLogicalFunction::getChildren() const { return parameters; } + +LogicalFunction AlwaysNeTfloatFloatLogicalFunction::withChildren(const std::vector& children) const +{ + PRECONDITION(children.size() == 3, "AlwaysNeTfloatFloatLogicalFunction requires 3 children, but got {}", children.size()); + auto copy = *this; copy.parameters = children; return copy; +} + +std::string_view AlwaysNeTfloatFloatLogicalFunction::getType() const { return NAME; } + +bool AlwaysNeTfloatFloatLogicalFunction::operator==(const LogicalFunctionConcept& rhs) const +{ + if (const auto* other = dynamic_cast(&rhs)) + return parameters == other->parameters; + return false; +} + +std::string AlwaysNeTfloatFloatLogicalFunction::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 AlwaysNeTfloatFloatLogicalFunction::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 AlwaysNeTfloatFloatLogicalFunction::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::RegisterAlwaysNeTfloatFloatLogicalFunction( + LogicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.children.size() == 3, + "AlwaysNeTfloatFloatLogicalFunction 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 AlwaysNeTfloatFloatLogicalFunction(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 0c35460553..f80fb56ab9 100644 --- a/nes-logical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-logical-operators/src/Functions/Meos/CMakeLists.txt @@ -82,3 +82,9 @@ add_plugin(EverGtTfloatFloat LogicalFunction nes-logical-operators EverGtTfloatF add_plugin(EverLeTfloatFloat LogicalFunction nes-logical-operators EverLeTfloatFloatLogicalFunction.cpp) add_plugin(EverLtTfloatFloat LogicalFunction nes-logical-operators EverLtTfloatFloatLogicalFunction.cpp) add_plugin(EverNeTfloatFloat LogicalFunction nes-logical-operators EverNeTfloatFloatLogicalFunction.cpp) +add_plugin(AlwaysEqTfloatFloat LogicalFunction nes-logical-operators AlwaysEqTfloatFloatLogicalFunction.cpp) +add_plugin(AlwaysGeTfloatFloat LogicalFunction nes-logical-operators AlwaysGeTfloatFloatLogicalFunction.cpp) +add_plugin(AlwaysGtTfloatFloat LogicalFunction nes-logical-operators AlwaysGtTfloatFloatLogicalFunction.cpp) +add_plugin(AlwaysLeTfloatFloat LogicalFunction nes-logical-operators AlwaysLeTfloatFloatLogicalFunction.cpp) +add_plugin(AlwaysLtTfloatFloat LogicalFunction nes-logical-operators AlwaysLtTfloatFloatLogicalFunction.cpp) +add_plugin(AlwaysNeTfloatFloat LogicalFunction nes-logical-operators AlwaysNeTfloatFloatLogicalFunction.cpp) diff --git a/nes-physical-operators/include/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..0e439990e7 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.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 `always_eq_tfloat_float`. + * + * Per-event always_eq_tfloat_float: tests if a single-instant tfloat value always equals a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AlwaysEqTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AlwaysEqTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/AlwaysGeTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..4bda09b03d --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.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 `always_ge_tfloat_float`. + * + * Per-event always_ge_tfloat_float: tests if a single-instant tfloat value always is greater than or equal to a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AlwaysGeTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AlwaysGeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/AlwaysGtTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..7272583f06 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.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 `always_gt_tfloat_float`. + * + * Per-event always_gt_tfloat_float: tests if a single-instant tfloat value always is greater than a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AlwaysGtTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AlwaysGtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/AlwaysLeTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..38e9384ce4 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.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 `always_le_tfloat_float`. + * + * Per-event always_le_tfloat_float: tests if a single-instant tfloat value always is less than or equal to a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AlwaysLeTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AlwaysLeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/AlwaysLtTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..bce18200bf --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.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 `always_lt_tfloat_float`. + * + * Per-event always_lt_tfloat_float: tests if a single-instant tfloat value always is less than a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AlwaysLtTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AlwaysLtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/AlwaysNeTfloatFloatPhysicalFunction.hpp b/nes-physical-operators/include/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.hpp new file mode 100644 index 0000000000..bb6fd34c50 --- /dev/null +++ b/nes-physical-operators/include/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.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 `always_ne_tfloat_float`. + * + * Per-event always_ne_tfloat_float: tests if a single-instant tfloat value always is not equal to a threshold. + * + * Generated by tools/codegen/codegen_nebula.py. + */ +class AlwaysNeTfloatFloatPhysicalFunction : public PhysicalFunctionConcept { +public: + AlwaysNeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + 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/AlwaysEqTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..d80ba1d066 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AlwaysEqTfloatFloatPhysicalFunction.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 { + +AlwaysEqTfloatFloatPhysicalFunction::AlwaysEqTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AlwaysEqTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = always_eq_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAlwaysEqTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AlwaysEqTfloatFloatPhysicalFunction 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 AlwaysEqTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..58d7b4dfa2 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AlwaysGeTfloatFloatPhysicalFunction.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 { + +AlwaysGeTfloatFloatPhysicalFunction::AlwaysGeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AlwaysGeTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = always_ge_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAlwaysGeTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AlwaysGeTfloatFloatPhysicalFunction 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 AlwaysGeTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..734a308e51 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AlwaysGtTfloatFloatPhysicalFunction.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 { + +AlwaysGtTfloatFloatPhysicalFunction::AlwaysGtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AlwaysGtTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = always_gt_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAlwaysGtTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AlwaysGtTfloatFloatPhysicalFunction 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 AlwaysGtTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..8fbcab93d5 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AlwaysLeTfloatFloatPhysicalFunction.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 { + +AlwaysLeTfloatFloatPhysicalFunction::AlwaysLeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AlwaysLeTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = always_le_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAlwaysLeTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AlwaysLeTfloatFloatPhysicalFunction 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 AlwaysLeTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..e3c12b1c89 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AlwaysLtTfloatFloatPhysicalFunction.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 { + +AlwaysLtTfloatFloatPhysicalFunction::AlwaysLtTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AlwaysLtTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = always_lt_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAlwaysLtTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AlwaysLtTfloatFloatPhysicalFunction 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 AlwaysLtTfloatFloatPhysicalFunction(std::move(arg0), std::move(arg1), std::move(arg2)); +} + +} // namespace NES diff --git a/nes-physical-operators/src/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.cpp b/nes-physical-operators/src/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.cpp new file mode 100644 index 0000000000..769c701a99 --- /dev/null +++ b/nes-physical-operators/src/Functions/Meos/AlwaysNeTfloatFloatPhysicalFunction.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 { + +AlwaysNeTfloatFloatPhysicalFunction::AlwaysNeTfloatFloatPhysicalFunction(PhysicalFunction valueFunction, + PhysicalFunction thresholdFunction, + PhysicalFunction tsFunction) +{ + parameterFunctions.reserve(3); + parameterFunctions.push_back(std::move(valueFunction)); + parameterFunctions.push_back(std::move(thresholdFunction)); + parameterFunctions.push_back(std::move(tsFunction)); +} + +VarVal AlwaysNeTfloatFloatPhysicalFunction::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 threshold = parameterValues[1].cast>(); + auto ts = parameterValues[2].cast>(); + + const auto result = nautilus::invoke( + +[](double value, double threshold, 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; + int r = always_ne_tfloat_float(temp, threshold); + free(temp); + return static_cast(r); + } catch (const std::exception&) { return 0.0; } + }, + value, threshold, ts); + + return VarVal(result); +} + +PhysicalFunctionRegistryReturnType PhysicalFunctionGeneratedRegistrar::RegisterAlwaysNeTfloatFloatPhysicalFunction( + PhysicalFunctionRegistryArguments arguments) +{ + PRECONDITION(arguments.childFunctions.size() == 3, + "AlwaysNeTfloatFloatPhysicalFunction 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 AlwaysNeTfloatFloatPhysicalFunction(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 43cddd97b6..1cf15e45be 100644 --- a/nes-physical-operators/src/Functions/Meos/CMakeLists.txt +++ b/nes-physical-operators/src/Functions/Meos/CMakeLists.txt @@ -81,4 +81,10 @@ add_plugin(EverGtTfloatFloat PhysicalFunction nes-physical-operators EverGtTfloa add_plugin(EverLeTfloatFloat PhysicalFunction nes-physical-operators EverLeTfloatFloatPhysicalFunction.cpp) add_plugin(EverLtTfloatFloat PhysicalFunction nes-physical-operators EverLtTfloatFloatPhysicalFunction.cpp) add_plugin(EverNeTfloatFloat PhysicalFunction nes-physical-operators EverNeTfloatFloatPhysicalFunction.cpp) +add_plugin(AlwaysEqTfloatFloat PhysicalFunction nes-physical-operators AlwaysEqTfloatFloatPhysicalFunction.cpp) +add_plugin(AlwaysGeTfloatFloat PhysicalFunction nes-physical-operators AlwaysGeTfloatFloatPhysicalFunction.cpp) +add_plugin(AlwaysGtTfloatFloat PhysicalFunction nes-physical-operators AlwaysGtTfloatFloatPhysicalFunction.cpp) +add_plugin(AlwaysLeTfloatFloat PhysicalFunction nes-physical-operators AlwaysLeTfloatFloatPhysicalFunction.cpp) +add_plugin(AlwaysLtTfloatFloat PhysicalFunction nes-physical-operators AlwaysLtTfloatFloatPhysicalFunction.cpp) +add_plugin(AlwaysNeTfloatFloat PhysicalFunction nes-physical-operators AlwaysNeTfloatFloatPhysicalFunction.cpp) endif() diff --git a/nes-sql-parser/AntlrSQL.g4 b/nes-sql-parser/AntlrSQL.g4 index ec195f471d..28cd19856c 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 | EVER_EQ_TFLOAT_FLOAT | EVER_GE_TFLOAT_FLOAT | EVER_GT_TFLOAT_FLOAT | EVER_LE_TFLOAT_FLOAT | EVER_LT_TFLOAT_FLOAT | EVER_NE_TFLOAT_FLOAT | TGEO_AT_STBOX | ADD_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_EXP | TFLOAT_FLOOR | TFLOAT_LN | TFLOAT_LOG10 | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TBIGINT_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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; +functionName: IDENTIFIER | AVG | MAX | MIN | SUM | COUNT | MEDIAN | ARRAY_AGG | VAR | TEMPORAL_SEQUENCE | TEMPORAL_EINTERSECTS_GEOMETRY | TEMPORAL_AINTERSECTS_GEOMETRY | TEMPORAL_ECONTAINS_GEOMETRY | ALWAYS_EQ_TFLOAT_FLOAT | ALWAYS_GE_TFLOAT_FLOAT | ALWAYS_GT_TFLOAT_FLOAT | ALWAYS_LE_TFLOAT_FLOAT | ALWAYS_LT_TFLOAT_FLOAT | ALWAYS_NE_TFLOAT_FLOAT | EDWITHIN_TGEO_GEO | EVER_EQ_TFLOAT_FLOAT | EVER_GE_TFLOAT_FLOAT | EVER_GT_TFLOAT_FLOAT | EVER_LE_TFLOAT_FLOAT | EVER_LT_TFLOAT_FLOAT | EVER_NE_TFLOAT_FLOAT | TGEO_AT_STBOX | ADD_BIGINT_TBIGINT | ADD_FLOAT_TFLOAT | ADD_INT_TINT | ADD_TBIGINT_BIGINT | ADD_TFLOAT_FLOAT | ADD_TINT_INT | ADD_TNUMBER_TNUMBER | DIV_BIGINT_TBIGINT | DIV_FLOAT_TFLOAT | DIV_INT_TINT | DIV_TBIGINT_BIGINT | DIV_TFLOAT_FLOAT | DIV_TINT_INT | DIV_TNUMBER_TNUMBER | MUL_BIGINT_TBIGINT | MUL_FLOAT_TFLOAT | MUL_INT_TINT | MUL_TBIGINT_BIGINT | MUL_TFLOAT_FLOAT | MUL_TINT_INT | MUL_TNUMBER_TNUMBER | SUB_BIGINT_TBIGINT | SUB_FLOAT_TFLOAT | SUB_INT_TINT | SUB_TBIGINT_BIGINT | 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_EXP | TFLOAT_FLOOR | TFLOAT_LN | TFLOAT_LOG10 | TFLOAT_RADIANS | TFLOAT_SCALE_VALUE | TFLOAT_SHIFT_SCALE_VALUE | TBIGINT_SCALE_VALUE | TBIGINT_SHIFT_SCALE_VALUE | TBIGINT_SHIFT_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)*; @@ -486,6 +486,12 @@ TEMPORAL_SEQUENCE: 'TEMPORAL_SEQUENCE' | 'temporal_sequence'; TEMPORAL_EINTERSECTS_GEOMETRY: 'TEMPORAL_EINTERSECTS_GEOMETRY' | 'temporal_eintersects_geometry'; TEMPORAL_AINTERSECTS_GEOMETRY: 'TEMPORAL_AINTERSECTS_GEOMETRY' | 'temporal_aintersects_geometry'; TEMPORAL_ECONTAINS_GEOMETRY: 'TEMPORAL_ECONTAINS_GEOMETRY' | 'temporal_econtains_geometry'; +ALWAYS_EQ_TFLOAT_FLOAT: 'ALWAYS_EQ_TFLOAT_FLOAT' | 'always_eq_tfloat_float'; +ALWAYS_GE_TFLOAT_FLOAT: 'ALWAYS_GE_TFLOAT_FLOAT' | 'always_ge_tfloat_float'; +ALWAYS_GT_TFLOAT_FLOAT: 'ALWAYS_GT_TFLOAT_FLOAT' | 'always_gt_tfloat_float'; +ALWAYS_LE_TFLOAT_FLOAT: 'ALWAYS_LE_TFLOAT_FLOAT' | 'always_le_tfloat_float'; +ALWAYS_LT_TFLOAT_FLOAT: 'ALWAYS_LT_TFLOAT_FLOAT' | 'always_lt_tfloat_float'; +ALWAYS_NE_TFLOAT_FLOAT: 'ALWAYS_NE_TFLOAT_FLOAT' | 'always_ne_tfloat_float'; EDWITHIN_TGEO_GEO: 'EDWITHIN_TGEO_GEO' | 'edwithin_tgeo_geo'; EVER_EQ_TFLOAT_FLOAT: 'EVER_EQ_TFLOAT_FLOAT' | 'ever_eq_tfloat_float'; EVER_GE_TFLOAT_FLOAT: 'EVER_GE_TFLOAT_FLOAT' | 'ever_ge_tfloat_float'; diff --git a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp index 545ac88c27..40fe84a909 100644 --- a/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp +++ b/nes-sql-parser/src/AntlrSQLQueryPlanCreator.cpp @@ -133,6 +133,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -3094,6 +3100,180 @@ void AntlrSQLQueryPlanCreator::exitFunctionCall(AntlrSQLParser::FunctionCallCont } break; /* END CODEGEN PARSER GLUE: EVER_NE_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ALWAYS_EQ_TFLOAT_FLOAT */ + case AntlrSQLLexer::ALWAYS_EQ_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ALWAYS_EQ_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(AlwaysEqTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ALWAYS_EQ_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ALWAYS_GE_TFLOAT_FLOAT */ + case AntlrSQLLexer::ALWAYS_GE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ALWAYS_GE_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(AlwaysGeTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ALWAYS_GE_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ALWAYS_GT_TFLOAT_FLOAT */ + case AntlrSQLLexer::ALWAYS_GT_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ALWAYS_GT_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(AlwaysGtTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ALWAYS_GT_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ALWAYS_LE_TFLOAT_FLOAT */ + case AntlrSQLLexer::ALWAYS_LE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ALWAYS_LE_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(AlwaysLeTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ALWAYS_LE_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ALWAYS_LT_TFLOAT_FLOAT */ + case AntlrSQLLexer::ALWAYS_LT_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ALWAYS_LT_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(AlwaysLtTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ALWAYS_LT_TFLOAT_FLOAT */ + /* BEGIN CODEGEN PARSER GLUE: ALWAYS_NE_TFLOAT_FLOAT */ + case AntlrSQLLexer::ALWAYS_NE_TFLOAT_FLOAT: + { + const auto argCount = context->expression().size(); + if (argCount != 3) + throw InvalidQuerySyntax("ALWAYS_NE_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(AlwaysNeTfloatFloatLogicalFunction(a0, a1, a2)); + } + break; + /* END CODEGEN PARSER GLUE: ALWAYS_NE_TFLOAT_FLOAT */ default: /// Check if the function is a constructor for a datatype