Skip to content

Commit

Permalink
Merge branch 'main' into bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Aug 9, 2024
2 parents bdc42eb + 950d776 commit 6d6eb31
Show file tree
Hide file tree
Showing 77 changed files with 923 additions and 158 deletions.
1 change: 1 addition & 0 deletions data/csv/auto/invalid_time.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12:0
4 changes: 4 additions & 0 deletions data/csv/auto/time.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
time
05:40
21:30
17:45
1 change: 1 addition & 0 deletions data/csv/auto/various_time_formats.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12:,12:0,12:00,12:0:,12:00:
2 changes: 1 addition & 1 deletion src/common/adbc/adbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ AdbcStatusCode StatementExecuteQuery(struct AdbcStatement *statement, struct Arr
}
duckdb::unique_ptr<duckdb::DataChunk> chunk;
auto prepared_statement_params =
reinterpret_cast<duckdb::PreparedStatementWrapper *>(wrapper->statement)->statement->n_param;
reinterpret_cast<duckdb::PreparedStatementWrapper *>(wrapper->statement)->statement->named_param_map.size();

while ((chunk = result->Fetch()) != nullptr) {
if (chunk->size() == 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,8 @@ const char* EnumUtil::ToChars<ExplainFormat>(ExplainFormat value) {
return "TEXT";
case ExplainFormat::JSON:
return "JSON";
case ExplainFormat::GRAPHVIZ:
return "GRAPHVIZ";
default:
throw NotImplementedException(StringUtil::Format("Enum value: '%d' not implemented", value));
}
Expand All @@ -2079,6 +2081,9 @@ ExplainFormat EnumUtil::FromString<ExplainFormat>(const char *value) {
if (StringUtil::Equals(value, "JSON")) {
return ExplainFormat::JSON;
}
if (StringUtil::Equals(value, "GRAPHVIZ")) {
return ExplainFormat::GRAPHVIZ;
}
throw NotImplementedException(StringUtil::Format("Enum value: '%s' not implemented", value));
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/sort/partition_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,21 +520,21 @@ bool PartitionGlobalMergeState::TryPrepareNextStage() {
return true;

case PartitionSortStage::PREPARE:
total_tasks = global_sort->sorted_blocks.size() / 2;
if (!total_tasks) {
if (!(global_sort->sorted_blocks.size() / 2)) {
break;
}
stage = PartitionSortStage::MERGE;
global_sort->InitializeMergeRound();
total_tasks = num_threads;
return true;

case PartitionSortStage::MERGE:
global_sort->CompleteMergeRound(true);
total_tasks = global_sort->sorted_blocks.size() / 2;
if (!total_tasks) {
if (!(global_sort->sorted_blocks.size() / 2)) {
break;
}
global_sort->InitializeMergeRound();
total_tasks = num_threads;
return true;

case PartitionSortStage::SORTED:
Expand Down
3 changes: 3 additions & 0 deletions src/common/tree_renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "duckdb/common/tree_renderer.hpp"
#include "duckdb/common/tree_renderer/text_tree_renderer.hpp"
#include "duckdb/common/tree_renderer/json_tree_renderer.hpp"
#include "duckdb/common/tree_renderer/graphviz_tree_renderer.hpp"

#include <sstream>

Expand All @@ -13,6 +14,8 @@ unique_ptr<TreeRenderer> TreeRenderer::CreateRenderer(ExplainFormat format) {
return make_uniq<TextTreeRenderer>();
case ExplainFormat::JSON:
return make_uniq<JSONTreeRenderer>();
case ExplainFormat::GRAPHVIZ:
return make_uniq<GRAPHVIZTreeRenderer>();
default:
throw NotImplementedException("ExplainFormat %s not implemented", EnumUtil::ToString(format));
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/tree_renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library_unity(duckdb_common_tree_renderer OBJECT json_tree_renderer.cpp
text_tree_renderer.cpp)
text_tree_renderer.cpp graphviz_tree_renderer.cpp)
set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:duckdb_common_tree_renderer>
PARENT_SCOPE)
108 changes: 108 additions & 0 deletions src/common/tree_renderer/graphviz_tree_renderer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "duckdb/common/tree_renderer/graphviz_tree_renderer.hpp"

#include "duckdb/common/pair.hpp"
#include "duckdb/common/string_util.hpp"
#include "duckdb/execution/operator/aggregate/physical_hash_aggregate.hpp"
#include "duckdb/execution/operator/join/physical_delim_join.hpp"
#include "duckdb/execution/operator/scan/physical_positional_scan.hpp"
#include "duckdb/execution/physical_operator.hpp"
#include "duckdb/parallel/pipeline.hpp"
#include "duckdb/planner/logical_operator.hpp"
#include "duckdb/main/query_profiler.hpp"
#include "utf8proc_wrapper.hpp"

#include <sstream>

namespace duckdb {

string GRAPHVIZTreeRenderer::ToString(const LogicalOperator &op) {
std::stringstream ss;
Render(op, ss);
return ss.str();
}

string GRAPHVIZTreeRenderer::ToString(const PhysicalOperator &op) {
std::stringstream ss;
Render(op, ss);
return ss.str();
}

string GRAPHVIZTreeRenderer::ToString(const ProfilingNode &op) {
std::stringstream ss;
Render(op, ss);
return ss.str();
}

string GRAPHVIZTreeRenderer::ToString(const Pipeline &op) {
std::stringstream ss;
Render(op, ss);
return ss.str();
}

void GRAPHVIZTreeRenderer::Render(const LogicalOperator &op, std::ostream &ss) {
auto tree = RenderTree::CreateRenderTree(op);
ToStream(*tree, ss);
}

void GRAPHVIZTreeRenderer::Render(const PhysicalOperator &op, std::ostream &ss) {
auto tree = RenderTree::CreateRenderTree(op);
ToStream(*tree, ss);
}

void GRAPHVIZTreeRenderer::Render(const ProfilingNode &op, std::ostream &ss) {
auto tree = RenderTree::CreateRenderTree(op);
ToStream(*tree, ss);
}

void GRAPHVIZTreeRenderer::Render(const Pipeline &op, std::ostream &ss) {
auto tree = RenderTree::CreateRenderTree(op);
ToStream(*tree, ss);
}

void GRAPHVIZTreeRenderer::ToStream(RenderTree &root, std::ostream &ss) {
const string digraph_format = R"(
digraph G {
node [shape=box, style=rounded, fontname="Courier New", fontsize=10];
%s
%s
}
)";

vector<string> nodes;
vector<string> edges;

const string node_format = R"( node_%d_%d [label="%s"];)";

for (idx_t y = 0; y < root.height; y++) {
for (idx_t x = 0; x < root.width; x++) {
auto node = root.GetNode(x, y);
if (!node) {
continue;
}

// Create Node
vector<string> body;
body.push_back(node->name);
for (auto &item : node->extra_text) {
auto &key = item.first;
auto &value_raw = item.second;

auto value = QueryProfiler::JSONSanitize(value_raw);
body.push_back(StringUtil::Format("%s:\\n%s", key, value));
}
nodes.push_back(StringUtil::Format(node_format, x, y, StringUtil::Join(body, "\\n───\\n")));

// Create Edge(s)
for (auto &coord : node->child_positions) {
edges.push_back(StringUtil::Format(" node_%d_%d -> node_%d_%d;", x, y, coord.x, coord.y));
}
}
}
auto node_lines = StringUtil::Join(nodes, "\n");
auto edge_lines = StringUtil::Join(edges, "\n");

string result = StringUtil::Format(digraph_format, node_lines, edge_lines);
ss << result;
}

} // namespace duckdb
44 changes: 27 additions & 17 deletions src/common/types/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <sstream>

namespace duckdb {

static_assert(sizeof(dtime_t) == sizeof(int64_t), "dtime_t was padded");

// string format is hh:mm:ss.microsecondsZ
Expand Down Expand Up @@ -65,27 +64,38 @@ bool Time::TryConvertInternal(const char *buf, idx_t len, idx_t &pos, dtime_t &r
// invalid separator
return false;
}

if (!Date::ParseDoubleDigit(buf, len, pos, min)) {
return false;
}
if (min < 0 || min >= 60) {
return false;
}

if (pos >= len) {
return false;
idx_t sep_pos = pos;
if (pos == len && !strict) {
min = 0;
} else {
if (!Date::ParseDoubleDigit(buf, len, pos, min)) {
return false;
}
if (min < 0 || min >= 60) {
return false;
}
}

if (buf[pos++] != sep) {
if (pos > len) {
return false;
}
if (pos == len && (!strict || sep_pos + 2 == pos)) {
sec = 0;
} else {
if (buf[pos++] != sep) {
return false;
}

if (!Date::ParseDoubleDigit(buf, len, pos, sec)) {
return false;
}
if (sec < 0 || sec >= 60) {
return false;
if (pos == len && !strict) {
sec = 0;
} else {
if (!Date::ParseDoubleDigit(buf, len, pos, sec)) {
return false;
}
if (sec < 0 || sec >= 60) {
return false;
}
}
}

micros = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/core_functions/function_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static const StaticFunctionDefinition internal_functions[] = {
DUCKDB_SCALAR_FUNCTION(StartsWithOperatorFun),
DUCKDB_SCALAR_FUNCTION_SET_ALIAS(AbsFun),
DUCKDB_SCALAR_FUNCTION(AcosFun),
DUCKDB_SCALAR_FUNCTION(AcoshFun),
DUCKDB_SCALAR_FUNCTION_SET(AgeFun),
DUCKDB_SCALAR_FUNCTION_ALIAS(AggregateFun),
DUCKDB_SCALAR_FUNCTION(AliasFun),
Expand Down Expand Up @@ -97,8 +98,10 @@ static const StaticFunctionDefinition internal_functions[] = {
DUCKDB_SCALAR_FUNCTION(ArrayValueFun),
DUCKDB_SCALAR_FUNCTION(ASCIIFun),
DUCKDB_SCALAR_FUNCTION(AsinFun),
DUCKDB_SCALAR_FUNCTION(AsinhFun),
DUCKDB_SCALAR_FUNCTION(AtanFun),
DUCKDB_SCALAR_FUNCTION(Atan2Fun),
DUCKDB_SCALAR_FUNCTION(AtanhFun),
DUCKDB_AGGREGATE_FUNCTION_SET(AvgFun),
DUCKDB_SCALAR_FUNCTION_SET(BarFun),
DUCKDB_SCALAR_FUNCTION_ALIAS(Base64Fun),
Expand All @@ -121,6 +124,7 @@ static const StaticFunctionDefinition internal_functions[] = {
DUCKDB_SCALAR_FUNCTION(ChrFun),
DUCKDB_AGGREGATE_FUNCTION(CorrFun),
DUCKDB_SCALAR_FUNCTION(CosFun),
DUCKDB_SCALAR_FUNCTION(CoshFun),
DUCKDB_SCALAR_FUNCTION(CotFun),
DUCKDB_AGGREGATE_FUNCTION(CovarPopFun),
DUCKDB_AGGREGATE_FUNCTION(CovarSampFun),
Expand Down Expand Up @@ -325,6 +329,7 @@ static const StaticFunctionDefinition internal_functions[] = {
DUCKDB_SCALAR_FUNCTION_SET(SignFun),
DUCKDB_SCALAR_FUNCTION_SET(SignBitFun),
DUCKDB_SCALAR_FUNCTION(SinFun),
DUCKDB_SCALAR_FUNCTION(SinhFun),
DUCKDB_AGGREGATE_FUNCTION(SkewnessFun),
DUCKDB_SCALAR_FUNCTION_ALIAS(SplitFun),
DUCKDB_SCALAR_FUNCTION(SqrtFun),
Expand All @@ -348,6 +353,7 @@ static const StaticFunctionDefinition internal_functions[] = {
DUCKDB_AGGREGATE_FUNCTION_SET(SumNoOverflowFun),
DUCKDB_AGGREGATE_FUNCTION_ALIAS(SumkahanFun),
DUCKDB_SCALAR_FUNCTION(TanFun),
DUCKDB_SCALAR_FUNCTION(TanhFun),
DUCKDB_SCALAR_FUNCTION_SET(TimeBucketFun),
DUCKDB_SCALAR_FUNCTION(TimeTZSortKeyFun),
DUCKDB_SCALAR_FUNCTION_SET(TimezoneFun),
Expand Down
42 changes: 42 additions & 0 deletions src/core_functions/scalar/math/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,47 @@
"description": "Truncates the number",
"example": "trunc(17.4)",
"type": "scalar_function_set"
},
{
"name": "cosh",
"parameters": "x",
"description": "Computes the hyperbolic cos of x",
"example": "cosh(1)",
"type": "scalar_function"
},
{
"name": "sinh",
"parameters": "x",
"description": "Computes the hyperbolic sin of x",
"example": "sinh(1)",
"type": "scalar_function"
},
{
"name": "tanh",
"parameters": "x",
"description": "Computes the hyperbolic tan of x",
"example": "tanh(1)",
"type": "scalar_function"
},
{
"name": "acosh",
"parameters": "x",
"description": "Computes the inverse hyperbolic cos of x",
"example": "acosh(0.5)",
"type": "scalar_function"
},
{
"name": "asinh",
"parameters": "x",
"description": "Computes the inverse hyperbolic sin of x",
"example": "asinh(0.5)",
"type": "scalar_function"
},
{
"name": "atanh",
"parameters": "x",
"description": "Computes the inverse hyperbolic tan of x",
"example": "atanh(0.5)",
"type": "scalar_function"
}
]
Loading

0 comments on commit 6d6eb31

Please sign in to comment.