MCPcopy Create free account
hub / github.com/BlazingDB/blazingsql / apply_interval_conversion

Function apply_interval_conversion

engine/src/parser/expression_utils.cpp:1425–1460  ·  view source on GitHub ↗

By default Calcite returns Interval types in ms unit. So we want to convert them to the right INTERVAL unit to do correct operations TODO: any issue related with INTERVAL operations (and parsing expressions) should be handled here

Source from the content-addressed store, hash-verified

1423// to do correct operations
1424// TODO: any issue related with INTERVAL operations (and parsing expressions) should be handled here
1425std::string apply_interval_conversion(std::string expression, std::vector<cudf::data_type> table_schema) {
1426 std::string interval_expr = ":INTERVAL";
1427 if (table_schema.size() == 0 || expression.find(interval_expr) == expression.npos) return expression;
1428
1429 // op with intervals
1430 if (expression.find("+") != expression.npos || expression.find("-") != expression.npos) {
1431 std::string plus_expr = "+($", sub_expr = "-($";
1432
1433 size_t start_pos = 0;
1434 if (expression.find(plus_expr) != expression.npos) {
1435 start_pos = expression.find(plus_expr) + plus_expr.size();
1436 } else if (expression.find(sub_expr) != expression.npos) {
1437 start_pos = expression.find(sub_expr) + sub_expr.size();
1438 }
1439
1440 std::string new_expr = expression.substr(start_pos, expression.size() - start_pos);
1441 size_t last_pos = new_expr.find(", ");
1442 new_expr = new_expr.substr(0, last_pos);
1443 int col_indice = std::stoi(new_expr);
1444
1445 if (table_schema[col_indice].id() == cudf::type_id::DURATION_SECONDS) {
1446 return StringUtil::replace(expression, "000" + interval_expr, interval_expr);
1447 } else if (table_schema[col_indice].id() == cudf::type_id::DURATION_MICROSECONDS) {
1448 return StringUtil::replace(expression, "000" + interval_expr, "000000" + interval_expr);
1449 } else if (table_schema[col_indice].id() == cudf::type_id::DURATION_NANOSECONDS) {
1450 return StringUtil::replace(expression, "000" + interval_expr, "000000000" + interval_expr);
1451 } else return expression; // duration ms
1452 }
1453
1454 // Literal interval
1455 if (expression.find("$") == expression.npos && expression.find("000:INTERVAL") != expression.npos) {
1456 return StringUtil::replace(expression, "000" + interval_expr, interval_expr);
1457 }
1458
1459 return expression;
1460}
1461
1462// For this function `indices` vector starts empty
1463// inputs:

Callers 1

preprocess_expressionFunction · 0.85

Calls 2

sizeMethod · 0.80
idMethod · 0.45

Tested by

no test coverage detected