Skip to content

Commit bd91268

Browse files
committed
Add math binary operators
1 parent dba0a2e commit bd91268

File tree

11 files changed

+1211
-18
lines changed

11 files changed

+1211
-18
lines changed

src/Storages/TimeSeries/PrometheusQueryToSQL/Converter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <Storages/TimeSeries/PrometheusQueryToSQL/ConverterContext.h>
44
#include <Storages/TimeSeries/PrometheusQueryToSQL/SQLQueryPiece.h>
5+
#include <Storages/TimeSeries/PrometheusQueryToSQL/applyBinaryOperator.h>
56
#include <Storages/TimeSeries/PrometheusQueryToSQL/applyFunction.h>
67
#include <Storages/TimeSeries/PrometheusQueryToSQL/applyOffset.h>
78
#include <Storages/TimeSeries/PrometheusQueryToSQL/applySubquery.h>
@@ -84,6 +85,14 @@ namespace
8485
return applyUnaryOperator(unary_operator, std::move(argument), context);
8586
}
8687

88+
case NodeType::BinaryOperator:
89+
{
90+
const auto * binary_operator = static_cast<const PQT::BinaryOperator *>(node);
91+
SQLQueryPiece left_argument = visitNode(binary_operator->getLeftArgument(), context);
92+
SQLQueryPiece right_argument = visitNode(binary_operator->getRightArgument(), context);
93+
return applyBinaryOperator(binary_operator, std::move(left_argument), std::move(right_argument), context);
94+
}
95+
8796
default:
8897
{
8998
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Prometheus query node type {} is not implemented", node->node_type);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <Storages/TimeSeries/PrometheusQueryToSQL/applyBinaryOperator.h>
2+
3+
#include <Common/Exception.h>
4+
#include <Storages/TimeSeries/PrometheusQueryToSQL/applyMathBinaryOperator.h>
5+
6+
7+
namespace DB::ErrorCodes
8+
{
9+
extern const int NOT_IMPLEMENTED;
10+
}
11+
12+
13+
namespace DB::PrometheusQueryToSQL
14+
{
15+
16+
SQLQueryPiece applyBinaryOperator(
17+
const PQT::BinaryOperator * operator_node, SQLQueryPiece && left_argument, SQLQueryPiece && right_argument, ConverterContext & context)
18+
{
19+
std::string_view operator_name = operator_node->operator_name;
20+
21+
if (isMathBinaryOperator(operator_name))
22+
return applyMathBinaryOperator(operator_node, std::move(left_argument), std::move(right_argument), context);
23+
24+
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Binary operator {} is not implemented", operator_name);
25+
}
26+
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <Storages/TimeSeries/PrometheusQueryToSQL/SQLQueryPiece.h>
4+
5+
6+
namespace DB::PrometheusQueryToSQL
7+
{
8+
9+
/// Applies a binary operator.
10+
SQLQueryPiece applyBinaryOperator(
11+
const PQT::BinaryOperator * operator_node, SQLQueryPiece && left_argument, SQLQueryPiece && right_argument, ConverterContext & context);
12+
13+
}

0 commit comments

Comments
 (0)