duckdb 0.7.1-dev43.0 → 0.7.1-dev49.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.7.1-dev43.0",
5
+ "version": "0.7.1-dev49.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -1554,16 +1554,22 @@ dtime_t Cast::Operation(string_t input) {
1554
1554
  //===--------------------------------------------------------------------===//
1555
1555
  template <>
1556
1556
  bool TryCastErrorMessage::Operation(string_t input, timestamp_t &result, string *error_message, bool strict) {
1557
- if (!TryCast::Operation<string_t, timestamp_t>(input, result, strict)) {
1557
+ auto cast_result = Timestamp::TryConvertTimestamp(input.GetDataUnsafe(), input.GetSize(), result);
1558
+ if (cast_result == TimestampCastResult::SUCCESS) {
1559
+ return true;
1560
+ }
1561
+ if (cast_result == TimestampCastResult::ERROR_INCORRECT_FORMAT) {
1558
1562
  HandleCastError::AssignError(Timestamp::ConversionError(input), error_message);
1559
- return false;
1563
+ } else {
1564
+ HandleCastError::AssignError(Timestamp::UnsupportedTimezoneError(input), error_message);
1560
1565
  }
1561
- return true;
1566
+ return false;
1562
1567
  }
1563
1568
 
1564
1569
  template <>
1565
1570
  bool TryCast::Operation(string_t input, timestamp_t &result, bool strict) {
1566
- return Timestamp::TryConvertTimestamp(input.GetDataUnsafe(), input.GetSize(), result);
1571
+ return Timestamp::TryConvertTimestamp(input.GetDataUnsafe(), input.GetSize(), result) ==
1572
+ TimestampCastResult::SUCCESS;
1567
1573
  }
1568
1574
 
1569
1575
  template <>
@@ -115,7 +115,7 @@ bool Time::TryConvertTime(const char *buf, idx_t len, idx_t &pos, dtime_t &resul
115
115
  if (!strict) {
116
116
  // last chance, check if we can parse as timestamp
117
117
  timestamp_t timestamp;
118
- if (Timestamp::TryConvertTimestamp(buf, len, timestamp)) {
118
+ if (Timestamp::TryConvertTimestamp(buf, len, timestamp) == TimestampCastResult::SUCCESS) {
119
119
  if (!Timestamp::IsFinite(timestamp)) {
120
120
  return false;
121
121
  }
@@ -88,11 +88,27 @@ bool Timestamp::TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &r
88
88
  return true;
89
89
  }
90
90
 
91
- bool Timestamp::TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result) {
91
+ TimestampCastResult Timestamp::TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result) {
92
92
  string_t tz(nullptr, 0);
93
93
  bool has_offset = false;
94
94
  // We don't understand TZ without an extension, so fail if one was provided.
95
- return TryConvertTimestampTZ(str, len, result, has_offset, tz) && !tz.GetSize();
95
+ auto success = TryConvertTimestampTZ(str, len, result, has_offset, tz);
96
+ if (!success) {
97
+ return TimestampCastResult::ERROR_INCORRECT_FORMAT;
98
+ }
99
+ if (tz.GetSize() == 0) {
100
+ // no timezone provided - success!
101
+ return TimestampCastResult::SUCCESS;
102
+ }
103
+ if (tz.GetSize() == 3) {
104
+ // we can ONLY handle UTC without ICU being loaded
105
+ auto tz_ptr = tz.GetDataUnsafe();
106
+ if ((tz_ptr[0] == 'u' || tz_ptr[0] == 'U') && (tz_ptr[1] == 't' || tz_ptr[1] == 'T') &&
107
+ (tz_ptr[2] == 'c' || tz_ptr[2] == 'C')) {
108
+ return TimestampCastResult::SUCCESS;
109
+ }
110
+ }
111
+ return TimestampCastResult::ERROR_NON_UTC_TIMEZONE;
96
112
  }
97
113
 
98
114
  string Timestamp::ConversionError(const string &str) {
@@ -101,16 +117,31 @@ string Timestamp::ConversionError(const string &str) {
101
117
  str);
102
118
  }
103
119
 
120
+ string Timestamp::UnsupportedTimezoneError(const string &str) {
121
+ return StringUtil::Format("timestamp field value \"%s\" has a timestamp that is not UTC.\nUse the TIMESTAMPTZ type "
122
+ "with the ICU extension loaded to handle non-UTC timestamps.",
123
+ str);
124
+ }
125
+
104
126
  string Timestamp::ConversionError(string_t str) {
105
127
  return Timestamp::ConversionError(str.GetString());
106
128
  }
107
129
 
130
+ string Timestamp::UnsupportedTimezoneError(string_t str) {
131
+ return Timestamp::UnsupportedTimezoneError(str.GetString());
132
+ }
133
+
108
134
  timestamp_t Timestamp::FromCString(const char *str, idx_t len) {
109
135
  timestamp_t result;
110
- if (!Timestamp::TryConvertTimestamp(str, len, result)) {
136
+ auto cast_result = Timestamp::TryConvertTimestamp(str, len, result);
137
+ if (cast_result == TimestampCastResult::SUCCESS) {
138
+ return result;
139
+ }
140
+ if (cast_result == TimestampCastResult::ERROR_NON_UTC_TIMEZONE) {
141
+ throw ConversionException(Timestamp::UnsupportedTimezoneError(string(str, len)));
142
+ } else {
111
143
  throw ConversionException(Timestamp::ConversionError(string(str, len)));
112
144
  }
113
- return result;
114
145
  }
115
146
 
116
147
  bool Timestamp::TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hour_offset, int &minute_offset) {
@@ -30,15 +30,10 @@ string BaseCSVReader::GetLineNumberStr(idx_t linenr, bool linenr_estimated) {
30
30
  return to_string(linenr + 1) + estimated;
31
31
  }
32
32
 
33
- BaseCSVReader::BaseCSVReader(FileSystem &fs_p, Allocator &allocator, FileOpener *opener_p,
34
- BufferedCSVReaderOptions options_p, const vector<LogicalType> &requested_types)
35
- : fs(fs_p), allocator(allocator), opener(opener_p), options(std::move(options_p)) {
36
- }
37
-
38
- BaseCSVReader::BaseCSVReader(ClientContext &context, BufferedCSVReaderOptions options_p,
33
+ BaseCSVReader::BaseCSVReader(ClientContext &context_p, BufferedCSVReaderOptions options_p,
39
34
  const vector<LogicalType> &requested_types)
40
- : BaseCSVReader(FileSystem::GetFileSystem(context), Allocator::Get(context), FileSystem::GetFileOpener(context),
41
- std::move(options_p), requested_types) {
35
+ : context(context_p), fs(FileSystem::GetFileSystem(context)), allocator(Allocator::Get(context)),
36
+ opener(FileSystem::GetFileOpener(context)), options(std::move(options_p)) {
42
37
  }
43
38
 
44
39
  BaseCSVReader::~BaseCSVReader() {
@@ -144,7 +139,7 @@ bool BaseCSVReader::TryCastValue(const Value &value, const LogicalType &sql_type
144
139
  } else {
145
140
  Value new_value;
146
141
  string error_message;
147
- return value.DefaultTryCastAs(sql_type, new_value, &error_message, true);
142
+ return value.TryCastAs(context, sql_type, new_value, &error_message, true);
148
143
  }
149
144
  }
150
145
 
@@ -481,8 +476,8 @@ bool BaseCSVReader::Flush(DataChunk &insert_chunk, bool try_add_line) {
481
476
  error_message, return_types[col_idx]);
482
477
  } else {
483
478
  // target type is not varchar: perform a cast
484
- success = VectorOperations::DefaultTryCast(parse_chunk.data[col_idx], insert_chunk.data[insert_idx],
485
- parse_chunk.size(), &error_message);
479
+ success = VectorOperations::TryCast(context, parse_chunk.data[col_idx], insert_chunk.data[insert_idx],
480
+ parse_chunk.size(), &error_message);
486
481
  }
487
482
  if (success) {
488
483
  continue;
@@ -23,25 +23,16 @@
23
23
 
24
24
  namespace duckdb {
25
25
 
26
- BufferedCSVReader::BufferedCSVReader(FileSystem &fs_p, Allocator &allocator, FileOpener *opener_p,
27
- BufferedCSVReaderOptions options_p, const vector<LogicalType> &requested_types)
28
- : BaseCSVReader(fs_p, allocator, opener_p, std::move(options_p), requested_types), buffer_size(0), position(0),
29
- start(0) {
30
- file_handle = OpenCSV(options);
31
- Initialize(requested_types);
32
- }
33
-
34
26
  BufferedCSVReader::BufferedCSVReader(ClientContext &context, BufferedCSVReaderOptions options_p,
35
27
  const vector<LogicalType> &requested_types)
36
- : BufferedCSVReader(FileSystem::GetFileSystem(context), Allocator::Get(context), FileSystem::GetFileOpener(context),
37
- std::move(options_p), requested_types) {
28
+ : BaseCSVReader(context, std::move(options_p), requested_types), buffer_size(0), position(0), start(0) {
29
+ file_handle = OpenCSV(options);
30
+ Initialize(requested_types);
38
31
  }
39
32
 
40
33
  BufferedCSVReader::BufferedCSVReader(ClientContext &context, string filename, BufferedCSVReaderOptions options_p,
41
34
  const vector<LogicalType> &requested_types)
42
- : BaseCSVReader(FileSystem::GetFileSystem(context), Allocator::Get(context), FileSystem::GetFileOpener(context),
43
- std::move(options_p), requested_types),
44
- buffer_size(0), position(0), start(0) {
35
+ : BaseCSVReader(context, std::move(options_p), requested_types), buffer_size(0), position(0), start(0) {
45
36
  options.file_path = std::move(filename);
46
37
  file_handle = OpenCSV(options);
47
38
  Initialize(requested_types);
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.1-dev43"
2
+ #define DUCKDB_VERSION "0.7.1-dev49"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "615a1b73e5"
5
+ #define DUCKDB_SOURCE_ID "d2ef69494e"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -93,6 +93,8 @@ struct timestamp_ns_t : public timestamp_t {}; // NOLINT
93
93
  struct timestamp_ms_t : public timestamp_t {}; // NOLINT
94
94
  struct timestamp_sec_t : public timestamp_t {}; // NOLINT
95
95
 
96
+ enum class TimestampCastResult : uint8_t { SUCCESS, ERROR_INCORRECT_FORMAT, ERROR_NON_UTC_TIMEZONE };
97
+
96
98
  //! The Timestamp class is a static class that holds helper functions for the Timestamp
97
99
  //! type.
98
100
  class Timestamp {
@@ -110,7 +112,7 @@ public:
110
112
  //! If the tz is not empty, the result is still an instant, but the parts can be extracted and applied to the TZ
111
113
  DUCKDB_API static bool TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset,
112
114
  string_t &tz);
113
- DUCKDB_API static bool TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
115
+ DUCKDB_API static TimestampCastResult TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result);
114
116
  DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len);
115
117
  //! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss"
116
118
  DUCKDB_API static string ToString(timestamp_t timestamp);
@@ -161,6 +163,8 @@ public:
161
163
 
162
164
  DUCKDB_API static string ConversionError(const string &str);
163
165
  DUCKDB_API static string ConversionError(string_t str);
166
+ DUCKDB_API static string UnsupportedTimezoneError(const string &str);
167
+ DUCKDB_API static string UnsupportedTimezoneError(string_t str);
164
168
  };
165
169
 
166
170
  } // namespace duckdb
@@ -35,11 +35,9 @@ class BaseCSVReader {
35
35
  public:
36
36
  BaseCSVReader(ClientContext &context, BufferedCSVReaderOptions options,
37
37
  const vector<LogicalType> &requested_types = vector<LogicalType>());
38
-
39
- BaseCSVReader(FileSystem &fs, Allocator &allocator, FileOpener *opener, BufferedCSVReaderOptions options,
40
- const vector<LogicalType> &requested_types = vector<LogicalType>());
41
38
  ~BaseCSVReader();
42
39
 
40
+ ClientContext &context;
43
41
  FileSystem &fs;
44
42
  Allocator &allocator;
45
43
  FileOpener *opener;
@@ -55,8 +55,6 @@ class BufferedCSVReader : public BaseCSVReader {
55
55
  public:
56
56
  BufferedCSVReader(ClientContext &context, BufferedCSVReaderOptions options,
57
57
  const vector<LogicalType> &requested_types = vector<LogicalType>());
58
- BufferedCSVReader(FileSystem &fs, Allocator &allocator, FileOpener *opener, BufferedCSVReaderOptions options,
59
- const vector<LogicalType> &requested_types = vector<LogicalType>());
60
58
  BufferedCSVReader(ClientContext &context, string filename, BufferedCSVReaderOptions options,
61
59
  const vector<LogicalType> &requested_types = vector<LogicalType>());
62
60
  ~BufferedCSVReader();