duckdb 0.5.2-dev1610.0 → 0.5.2-dev1616.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.5.2-dev1610.0",
5
+ "version": "0.5.2-dev1616.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -8195,6 +8195,56 @@ void DuckDBAssertInternal(bool condition, const char *condition_name, const char
8195
8195
 
8196
8196
 
8197
8197
 
8198
+ //===----------------------------------------------------------------------===//
8199
+ // DuckDB
8200
+ //
8201
+ // duckdb/common/profiler.hpp
8202
+ //
8203
+ //
8204
+ //===----------------------------------------------------------------------===//
8205
+
8206
+
8207
+
8208
+
8209
+
8210
+
8211
+ namespace duckdb {
8212
+
8213
+ //! The profiler can be used to measure elapsed time
8214
+ template <typename T>
8215
+ class BaseProfiler {
8216
+ public:
8217
+ //! Starts the timer
8218
+ void Start() {
8219
+ finished = false;
8220
+ start = Tick();
8221
+ }
8222
+ //! Finishes timing
8223
+ void End() {
8224
+ end = Tick();
8225
+ finished = true;
8226
+ }
8227
+
8228
+ //! Returns the elapsed time in seconds. If End() has been called, returns
8229
+ //! the total elapsed time. Otherwise returns how far along the timer is
8230
+ //! right now.
8231
+ double Elapsed() const {
8232
+ auto _end = finished ? end : Tick();
8233
+ return std::chrono::duration_cast<std::chrono::duration<double>>(_end - start).count();
8234
+ }
8235
+
8236
+ private:
8237
+ time_point<T> Tick() const {
8238
+ return T::now();
8239
+ }
8240
+ time_point<T> start;
8241
+ time_point<T> end;
8242
+ bool finished = false;
8243
+ };
8244
+
8245
+ using Profiler = BaseProfiler<system_clock>;
8246
+
8247
+ } // namespace duckdb
8198
8248
 
8199
8249
 
8200
8250
 
@@ -30079,6 +30129,72 @@ bool PreservedError::operator==(const PreservedError &other) const {
30079
30129
 
30080
30130
  } // namespace duckdb
30081
30131
 
30132
+ //===----------------------------------------------------------------------===//
30133
+ // DuckDB
30134
+ //
30135
+ // duckdb/common/progress_bar.hpp
30136
+ //
30137
+ //
30138
+ //===----------------------------------------------------------------------===//
30139
+
30140
+
30141
+
30142
+
30143
+
30144
+
30145
+
30146
+
30147
+ namespace duckdb {
30148
+
30149
+ class ProgressBar {
30150
+ public:
30151
+ explicit ProgressBar(Executor &executor, idx_t show_progress_after, bool print_progress);
30152
+
30153
+ //! Starts the thread
30154
+ void Start();
30155
+ //! Updates the progress bar and prints it to the screen
30156
+ void Update(bool final);
30157
+ //! Gets current percentage
30158
+ double GetCurrentPercentage();
30159
+
30160
+ private:
30161
+ static constexpr const idx_t PARTIAL_BLOCK_COUNT = 8;
30162
+ #ifndef DUCKDB_ASCII_TREE_RENDERER
30163
+ const char *PROGRESS_EMPTY = " ";
30164
+ const char *PROGRESS_PARTIAL[PARTIAL_BLOCK_COUNT] {
30165
+ " ", "\xE2\x96\x8F", "\xE2\x96\x8E", "\xE2\x96\x8D", "\xE2\x96\x8C", "\xE2\x96\x8B", "\xE2\x96\x8A",
30166
+ "\xE2\x96\x89"};
30167
+ const char *PROGRESS_BLOCK = "\xE2\x96\x88";
30168
+ const char *PROGRESS_START = "\xE2\x96\x95";
30169
+ const char *PROGRESS_END = "\xE2\x96\x8F";
30170
+ #else
30171
+ const char *PROGRESS_EMPTY = " ";
30172
+ const char *PROGRESS_PARTIAL[PARTIAL_BLOCK_COUNT] {" ", " ", " ", " ", " ", " ", " ", " "};
30173
+ const char *PROGRESS_BLOCK = "=";
30174
+ const char *PROGRESS_START = "[";
30175
+ const char *PROGRESS_END = "]";
30176
+ #endif
30177
+ static constexpr const idx_t PROGRESS_BAR_WIDTH = 60;
30178
+
30179
+ void PrintProgressInternal(int percentage);
30180
+ void PrintProgress(int percentage);
30181
+ void FinishProgressBarPrint();
30182
+
30183
+ private:
30184
+ //! The executor
30185
+ Executor &executor;
30186
+ //! The profiler used to measure the time since the progress bar was started
30187
+ Profiler profiler;
30188
+ //! The time in ms after which to start displaying the progress bar
30189
+ idx_t show_progress_after;
30190
+ //! The current progress percentage
30191
+ double current_percentage;
30192
+ //! Whether or not we print the progress bar
30193
+ bool print_progress;
30194
+ //! Whether or not profiling is supported for the current query
30195
+ bool supported = true;
30196
+ };
30197
+ } // namespace duckdb
30082
30198
 
30083
30199
 
30084
30200
 
@@ -30096,40 +30212,33 @@ bool PreservedError::operator==(const PreservedError &other) const {
30096
30212
 
30097
30213
  namespace duckdb {
30098
30214
 
30099
- // LCOV_EXCL_START
30100
- void Printer::Print(OutputStream stream, const string &str) {
30215
+ void Printer::RawPrint(OutputStream stream, const string &str) {
30101
30216
  #ifndef DUCKDB_DISABLE_PRINT
30102
30217
  #ifdef DUCKDB_WINDOWS
30103
30218
  if (IsTerminal(stream)) {
30104
30219
  // print utf8 to terminal
30105
30220
  auto unicode = WindowsUtil::UTF8ToMBCS(str.c_str());
30106
- fprintf(stream == OutputStream::STREAM_STDERR ? stderr : stdout, "%s\n", unicode.c_str());
30221
+ fprintf(stream == OutputStream::STREAM_STDERR ? stderr : stdout, "%s", unicode.c_str());
30107
30222
  return;
30108
30223
  }
30109
30224
  #endif
30110
- fprintf(stream == OutputStream::STREAM_STDERR ? stderr : stdout, "%s\n", str.c_str());
30225
+ fprintf(stream == OutputStream::STREAM_STDERR ? stderr : stdout, "%s", str.c_str());
30111
30226
  #endif
30112
30227
  }
30113
30228
 
30114
- void Printer::Print(const string &str) {
30115
- Printer::Print(OutputStream::STREAM_STDERR, str);
30229
+ // LCOV_EXCL_START
30230
+ void Printer::Print(OutputStream stream, const string &str) {
30231
+ Printer::RawPrint(stream, str);
30232
+ Printer::RawPrint(stream, "\n");
30116
30233
  }
30117
-
30118
- void Printer::PrintProgress(int percentage, const char *pbstr, int pbwidth) {
30234
+ void Printer::Flush(OutputStream stream) {
30119
30235
  #ifndef DUCKDB_DISABLE_PRINT
30120
- int lpad = (int)(percentage / 100.0 * pbwidth);
30121
- int rpad = pbwidth - lpad;
30122
- fprintf(stdout, "\r%3d%% [%.*s%*s]", percentage, lpad, pbstr, rpad, "");
30123
- fflush(stdout);
30236
+ fflush(stream == OutputStream::STREAM_STDERR ? stderr : stdout);
30124
30237
  #endif
30125
30238
  }
30126
30239
 
30127
- void Printer::FinishProgressBarPrint(const char *pbstr, int pbwidth) {
30128
- #ifndef DUCKDB_DISABLE_PRINT
30129
- PrintProgress(100, pbstr, pbwidth);
30130
- fprintf(stdout, " \n");
30131
- fflush(stdout);
30132
- #endif
30240
+ void Printer::Print(const string &str) {
30241
+ Printer::Print(OutputStream::STREAM_STDERR, str);
30133
30242
  }
30134
30243
 
30135
30244
  bool Printer::IsTerminal(OutputStream stream) {
@@ -30201,12 +30310,72 @@ void ProgressBar::Update(bool final) {
30201
30310
  current_percentage = new_percentage;
30202
30311
  }
30203
30312
  if (supported && print_progress && sufficient_time_elapsed && current_percentage > -1 && print_progress) {
30313
+ #ifndef DUCKDB_DISABLE_PRINT
30204
30314
  if (final) {
30205
- Printer::FinishProgressBarPrint(PROGRESS_BAR_STRING.c_str(), PROGRESS_BAR_WIDTH);
30315
+ FinishProgressBarPrint();
30206
30316
  } else {
30207
- Printer::PrintProgress(current_percentage, PROGRESS_BAR_STRING.c_str(), PROGRESS_BAR_WIDTH);
30317
+ PrintProgress(current_percentage);
30318
+ }
30319
+ #endif
30320
+ }
30321
+ }
30322
+
30323
+ void ProgressBar::PrintProgressInternal(int percentage) {
30324
+ if (percentage > 100) {
30325
+ percentage = 100;
30326
+ }
30327
+ if (percentage < 0) {
30328
+ percentage = 0;
30329
+ }
30330
+ string result;
30331
+ // we divide the number of blocks by the percentage
30332
+ // 0% = 0
30333
+ // 100% = PROGRESS_BAR_WIDTH
30334
+ // the percentage determines how many blocks we need to draw
30335
+ double blocks_to_draw = PROGRESS_BAR_WIDTH * (percentage / 100.0);
30336
+ // because of the power of unicode, we can also draw partial blocks
30337
+
30338
+ // render the percentage with some padding to ensure everything stays nicely aligned
30339
+ result = "\r";
30340
+ if (percentage < 100) {
30341
+ result += " ";
30342
+ }
30343
+ if (percentage < 10) {
30344
+ result += " ";
30345
+ }
30346
+ result += to_string(percentage) + "%";
30347
+ result += " ";
30348
+ result += PROGRESS_START;
30349
+ idx_t i;
30350
+ for (i = 0; i < idx_t(blocks_to_draw); i++) {
30351
+ result += PROGRESS_BLOCK;
30352
+ }
30353
+ if (i < PROGRESS_BAR_WIDTH) {
30354
+ // print a partial block based on the percentage of the progress bar remaining
30355
+ idx_t index = idx_t((blocks_to_draw - idx_t(blocks_to_draw)) * PARTIAL_BLOCK_COUNT);
30356
+ if (index >= PARTIAL_BLOCK_COUNT) {
30357
+ index = PARTIAL_BLOCK_COUNT - 1;
30208
30358
  }
30359
+ result += PROGRESS_PARTIAL[index];
30360
+ i++;
30361
+ }
30362
+ for (; i < PROGRESS_BAR_WIDTH; i++) {
30363
+ result += PROGRESS_EMPTY;
30209
30364
  }
30365
+ result += PROGRESS_END;
30366
+ result += " ";
30367
+
30368
+ Printer::RawPrint(OutputStream::STREAM_STDOUT, result);
30369
+ }
30370
+ void ProgressBar::PrintProgress(int percentage) {
30371
+ PrintProgressInternal(percentage);
30372
+ Printer::Flush(OutputStream::STREAM_STDOUT);
30373
+ }
30374
+
30375
+ void ProgressBar::FinishProgressBarPrint() {
30376
+ PrintProgressInternal(100);
30377
+ Printer::RawPrint(OutputStream::STREAM_STDOUT, "\n");
30378
+ Printer::Flush(OutputStream::STREAM_STDOUT);
30210
30379
  }
30211
30380
 
30212
30381
  } // namespace duckdb
@@ -123409,6 +123578,7 @@ static void WriteCSVSink(ExecutionContext &context, FunctionData &bind_data, Glo
123409
123578
 
123410
123579
  // first cast the columns of the chunk to varchar
123411
123580
  auto &cast_chunk = local_data.cast_chunk;
123581
+ cast_chunk.Reset();
123412
123582
  cast_chunk.SetCardinality(input);
123413
123583
  for (idx_t col_idx = 0; col_idx < input.ColumnCount(); col_idx++) {
123414
123584
  if (csv_data.sql_types[col_idx].id() == LogicalTypeId::VARCHAR) {
@@ -133384,6 +133554,7 @@ public:
133384
133554
 
133385
133555
 
133386
133556
 
133557
+
133387
133558
  namespace duckdb {
133388
133559
 
133389
133560
  struct ActiveQueryContext {