duckdb 0.3.2-dev556.0 → 0.3.2-dev581.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.2-dev556.0",
4
+ "version": "0.3.2-dev581.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -5475,14 +5475,15 @@ string TypeCatalogEntry::ToSQL() {
5475
5475
  std::stringstream ss;
5476
5476
  switch (user_type->id()) {
5477
5477
  case (LogicalTypeId::ENUM): {
5478
- auto values_insert_order = EnumType::GetValuesInsertOrder(*user_type);
5478
+ Vector values_insert_order(EnumType::GetValuesInsertOrder(*user_type));
5479
+ idx_t size = EnumType::GetSize(*user_type);
5479
5480
  ss << "CREATE TYPE ";
5480
5481
  ss << name;
5481
5482
  ss << " AS ENUM ( ";
5482
5483
 
5483
- for (idx_t i = 0; i < values_insert_order.size(); i++) {
5484
- ss << "'" << values_insert_order[i] << "'";
5485
- if (i != values_insert_order.size() - 1) {
5484
+ for (idx_t i = 0; i < size; i++) {
5485
+ ss << "'" << values_insert_order.GetValue(i).ToString() << "'";
5486
+ if (i != size - 1) {
5486
5487
  ss << ", ";
5487
5488
  }
5488
5489
  }
@@ -32897,6 +32898,8 @@ public:
32897
32898
 
32898
32899
 
32899
32900
 
32901
+
32902
+
32900
32903
  namespace duckdb {
32901
32904
 
32902
32905
  DataChunk::DataChunk() : count(0), capacity(STANDARD_VECTOR_SIZE) {
@@ -33299,6 +33302,79 @@ void SetStructMap(DuckDBArrowArrayChildHolder &child_holder, const LogicalType &
33299
33302
  }
33300
33303
  }
33301
33304
 
33305
+ struct ArrowUUIDConversion {
33306
+ using internal_type_t = uint64_t;
33307
+
33308
+ static unique_ptr<Vector> InitializeVector(Vector &data, idx_t size) {
33309
+ return make_unique<Vector>(LogicalType::VARCHAR, size);
33310
+ }
33311
+
33312
+ static idx_t GetStringLength(uint64_t value) {
33313
+ return UUID::STRING_SIZE;
33314
+ }
33315
+
33316
+ static string_t ConvertValue(Vector &tgt_vec, string_t *tgt_ptr, internal_type_t *src_ptr, idx_t row) {
33317
+ auto str_value = UUID::ToString(src_ptr[row]);
33318
+ // Have to store this string
33319
+ tgt_ptr[row] = StringVector::AddStringOrBlob(tgt_vec, str_value);
33320
+ return tgt_ptr[row];
33321
+ }
33322
+ };
33323
+
33324
+ struct ArrowVarcharConversion {
33325
+ using internal_type_t = string_t;
33326
+
33327
+ static unique_ptr<Vector> InitializeVector(Vector &data, idx_t size) {
33328
+ return make_unique<Vector>(data);
33329
+ }
33330
+ static idx_t GetStringLength(string_t value) {
33331
+ return value.GetSize();
33332
+ }
33333
+
33334
+ static string_t ConvertValue(Vector &tgt_vec, string_t *tgt_ptr, internal_type_t *src_ptr, idx_t row) {
33335
+ return src_ptr[row];
33336
+ }
33337
+ };
33338
+
33339
+ template <class CONVERT, class VECTOR_TYPE>
33340
+ void SetVarchar(DuckDBArrowArrayChildHolder &child_holder, const LogicalType &type, Vector &data, idx_t size) {
33341
+ auto &child = child_holder.array;
33342
+ child_holder.vector = CONVERT::InitializeVector(data, size);
33343
+ auto target_data_ptr = FlatVector::GetData<string_t>(data);
33344
+ child.n_buffers = 3;
33345
+ child_holder.offsets = unique_ptr<data_t[]>(new data_t[sizeof(uint32_t) * (size + 1)]);
33346
+ child.buffers[1] = child_holder.offsets.get();
33347
+ D_ASSERT(child.buffers[1]);
33348
+ //! step 1: figure out total string length:
33349
+ idx_t total_string_length = 0;
33350
+ auto source_ptr = FlatVector::GetData<VECTOR_TYPE>(data);
33351
+ auto &mask = FlatVector::Validity(data);
33352
+ for (idx_t row_idx = 0; row_idx < size; row_idx++) {
33353
+ if (!mask.RowIsValid(row_idx)) {
33354
+ continue;
33355
+ }
33356
+ total_string_length += CONVERT::GetStringLength(source_ptr[row_idx]);
33357
+ }
33358
+ //! step 2: allocate this much
33359
+ child_holder.data = unique_ptr<data_t[]>(new data_t[total_string_length]);
33360
+ child.buffers[2] = child_holder.data.get();
33361
+ D_ASSERT(child.buffers[2]);
33362
+ //! step 3: assign buffers
33363
+ idx_t current_heap_offset = 0;
33364
+ auto target_ptr = (uint32_t *)child.buffers[1];
33365
+
33366
+ for (idx_t row_idx = 0; row_idx < size; row_idx++) {
33367
+ target_ptr[row_idx] = current_heap_offset;
33368
+ if (!mask.RowIsValid(row_idx)) {
33369
+ continue;
33370
+ }
33371
+ string_t str = CONVERT::ConvertValue(*child_holder.vector, target_data_ptr, source_ptr, row_idx);
33372
+ memcpy((void *)((uint8_t *)child.buffers[2] + current_heap_offset), str.GetDataUnsafe(), str.GetSize());
33373
+ current_heap_offset += str.GetSize();
33374
+ }
33375
+ target_ptr[size] = current_heap_offset; //! need to terminate last string!
33376
+ }
33377
+
33302
33378
  void SetArrowChild(DuckDBArrowArrayChildHolder &child_holder, const LogicalType &type, Vector &data, idx_t size) {
33303
33379
  auto &child = child_holder.array;
33304
33380
  switch (type.id()) {
@@ -33404,39 +33480,11 @@ void SetArrowChild(DuckDBArrowArrayChildHolder &child_holder, const LogicalType
33404
33480
  }
33405
33481
  case LogicalTypeId::BLOB:
33406
33482
  case LogicalTypeId::VARCHAR: {
33407
- child_holder.vector = make_unique<Vector>(data);
33408
- child.n_buffers = 3;
33409
- child_holder.offsets = unique_ptr<data_t[]>(new data_t[sizeof(uint32_t) * (size + 1)]);
33410
- child.buffers[1] = child_holder.offsets.get();
33411
- D_ASSERT(child.buffers[1]);
33412
- //! step 1: figure out total string length:
33413
- idx_t total_string_length = 0;
33414
- auto string_t_ptr = FlatVector::GetData<string_t>(*child_holder.vector);
33415
- auto &mask = FlatVector::Validity(*child_holder.vector);
33416
- for (idx_t row_idx = 0; row_idx < size; row_idx++) {
33417
- if (!mask.RowIsValid(row_idx)) {
33418
- continue;
33419
- }
33420
- total_string_length += string_t_ptr[row_idx].GetSize();
33421
- }
33422
- //! step 2: allocate this much
33423
- child_holder.data = unique_ptr<data_t[]>(new data_t[total_string_length]);
33424
- child.buffers[2] = child_holder.data.get();
33425
- D_ASSERT(child.buffers[2]);
33426
- //! step 3: assign buffers
33427
- idx_t current_heap_offset = 0;
33428
- auto target_ptr = (uint32_t *)child.buffers[1];
33429
-
33430
- for (idx_t row_idx = 0; row_idx < size; row_idx++) {
33431
- target_ptr[row_idx] = current_heap_offset;
33432
- if (!mask.RowIsValid(row_idx)) {
33433
- continue;
33434
- }
33435
- auto &str = string_t_ptr[row_idx];
33436
- memcpy((void *)((uint8_t *)child.buffers[2] + current_heap_offset), str.GetDataUnsafe(), str.GetSize());
33437
- current_heap_offset += str.GetSize();
33438
- }
33439
- target_ptr[size] = current_heap_offset; //! need to terminate last string!
33483
+ SetVarchar<ArrowVarcharConversion, string_t>(child_holder, type, data, size);
33484
+ break;
33485
+ }
33486
+ case LogicalTypeId::UUID: {
33487
+ SetVarchar<ArrowUUIDConversion, uint64_t>(child_holder, type, data, size);
33440
33488
  break;
33441
33489
  }
33442
33490
  case LogicalTypeId::LIST: {
@@ -33492,6 +33540,23 @@ void SetArrowChild(DuckDBArrowArrayChildHolder &child_holder, const LogicalType
33492
33540
  }
33493
33541
  break;
33494
33542
  }
33543
+ case LogicalTypeId::ENUM: {
33544
+ // We need to initialize our dictionary
33545
+ child_holder.children.resize(1);
33546
+ idx_t dict_size = EnumType::GetSize(type);
33547
+ InitializeChild(child_holder.children[0], dict_size);
33548
+ Vector dictionary(EnumType::GetValuesInsertOrder(type));
33549
+ SetArrowChild(child_holder.children[0], dictionary.GetType(), dictionary, dict_size);
33550
+ child_holder.children_ptrs.push_back(&child_holder.children[0].array);
33551
+
33552
+ // now we set the data
33553
+ child.dictionary = child_holder.children_ptrs[0];
33554
+ child_holder.vector = make_unique<Vector>(data);
33555
+ child.n_buffers = 2;
33556
+ child.buffers[1] = (void *)FlatVector::GetData(*child_holder.vector);
33557
+
33558
+ break;
33559
+ }
33495
33560
  default:
33496
33561
  throw std::runtime_error("Unsupported type " + type.ToString());
33497
33562
  }
@@ -38061,7 +38126,7 @@ string Value::ToString() const {
38061
38126
  default:
38062
38127
  throw InternalException("ENUM can only have unsigned integers (except UINT64) as physical types");
38063
38128
  }
38064
- return values_insert_order[enum_idx];
38129
+ return values_insert_order.GetValue(enum_idx).ToString();
38065
38130
  }
38066
38131
  default:
38067
38132
  throw NotImplementedException("Unimplemented type for printing: %s", type_.ToString());
@@ -40615,6 +40680,8 @@ const sel_t FlatVector::INCREMENTAL_VECTOR[] = {
40615
40680
 
40616
40681
 
40617
40682
 
40683
+
40684
+
40618
40685
  namespace duckdb {
40619
40686
 
40620
40687
  LogicalType::LogicalType() : LogicalType(LogicalTypeId::INVALID) {
@@ -41348,7 +41415,7 @@ struct ExtraTypeInfo {
41348
41415
  public:
41349
41416
  virtual bool Equals(ExtraTypeInfo *other) = 0;
41350
41417
  //! Serializes a ExtraTypeInfo to a stand-alone binary blob
41351
- virtual void Serialize(Serializer &serializer) const = 0;
41418
+ virtual void Serialize(Serializer &serializer) = 0;
41352
41419
  //! Serializes a ExtraTypeInfo to a stand-alone binary blob
41353
41420
  static void Serialize(ExtraTypeInfo *info, Serializer &serializer);
41354
41421
  //! Deserializes a blob back into an ExtraTypeInfo
@@ -41378,7 +41445,7 @@ public:
41378
41445
  return width == other.width && scale == other.scale;
41379
41446
  }
41380
41447
 
41381
- void Serialize(Serializer &serializer) const override {
41448
+ void Serialize(Serializer &serializer) override {
41382
41449
  serializer.Write<uint8_t>(width);
41383
41450
  serializer.Write<uint8_t>(scale);
41384
41451
  }
@@ -41425,7 +41492,7 @@ public:
41425
41492
  return true;
41426
41493
  }
41427
41494
 
41428
- void Serialize(Serializer &serializer) const override {
41495
+ void Serialize(Serializer &serializer) override {
41429
41496
  serializer.WriteString(collation);
41430
41497
  }
41431
41498
 
@@ -41473,7 +41540,7 @@ public:
41473
41540
  return child_type == other.child_type;
41474
41541
  }
41475
41542
 
41476
- void Serialize(Serializer &serializer) const override {
41543
+ void Serialize(Serializer &serializer) override {
41477
41544
  child_type.Serialize(serializer);
41478
41545
  }
41479
41546
 
@@ -41517,7 +41584,7 @@ public:
41517
41584
  return child_types == other.child_types;
41518
41585
  }
41519
41586
 
41520
- void Serialize(Serializer &serializer) const override {
41587
+ void Serialize(Serializer &serializer) override {
41521
41588
  serializer.Write<uint32_t>(child_types.size());
41522
41589
  for (idx_t i = 0; i < child_types.size(); i++) {
41523
41590
  serializer.WriteString(child_types[i].first);
@@ -41599,7 +41666,7 @@ public:
41599
41666
  return other.user_type_name == user_type_name;
41600
41667
  }
41601
41668
 
41602
- void Serialize(Serializer &serializer) const override {
41669
+ void Serialize(Serializer &serializer) override {
41603
41670
  serializer.WriteString(user_type_name);
41604
41671
  }
41605
41672
 
@@ -41625,12 +41692,13 @@ LogicalType LogicalType::USER(const string &user_type_name) {
41625
41692
  // Enum Type
41626
41693
  //===--------------------------------------------------------------------===//
41627
41694
  struct EnumTypeInfo : public ExtraTypeInfo {
41628
- explicit EnumTypeInfo(string enum_name_p, vector<string> values_insert_order_p)
41695
+ explicit EnumTypeInfo(string enum_name_p, Vector &values_insert_order_p, idx_t size)
41629
41696
  : ExtraTypeInfo(ExtraTypeInfoType::ENUM_TYPE_INFO), enum_name(move(enum_name_p)),
41630
- values_insert_order(std::move(values_insert_order_p)) {
41697
+ values_insert_order(values_insert_order_p), size(size) {
41631
41698
  }
41632
41699
  string enum_name;
41633
- vector<string> values_insert_order;
41700
+ Vector values_insert_order;
41701
+ idx_t size;
41634
41702
  TypeCatalogEntry *catalog_entry = nullptr;
41635
41703
 
41636
41704
  public:
@@ -41643,33 +41711,42 @@ public:
41643
41711
  return false;
41644
41712
  }
41645
41713
  auto &other = (EnumTypeInfo &)*other_p;
41646
- // We must check if all elements are equal
41647
- if (other.values_insert_order == values_insert_order) {
41648
- return true;
41714
+
41715
+ // We must check if both enums have the same size
41716
+ if (other.size != size) {
41717
+ return false;
41649
41718
  }
41650
- return false;
41719
+ auto other_vector_ptr = FlatVector::GetData<string_t>(other.values_insert_order);
41720
+ auto this_vector_ptr = FlatVector::GetData<string_t>(values_insert_order);
41721
+
41722
+ // Now we must check if all strings are the same
41723
+ for (idx_t i = 0; i < size; i++) {
41724
+ if (!Equals::Operation(other_vector_ptr[i], this_vector_ptr[i])) {
41725
+ return false;
41726
+ }
41727
+ }
41728
+ return true;
41651
41729
  }
41652
- void Serialize(Serializer &serializer) const override {
41653
- serializer.Write<uint32_t>(values_insert_order.size());
41730
+ void Serialize(Serializer &serializer) override {
41731
+ serializer.Write<uint32_t>(size);
41654
41732
  serializer.WriteString(enum_name);
41655
- serializer.WriteStringVector(values_insert_order);
41733
+ values_insert_order.Serialize(size, serializer);
41656
41734
  }
41657
41735
  };
41658
41736
 
41659
41737
  template <class T>
41660
41738
  struct EnumTypeInfoTemplated : public EnumTypeInfo {
41661
- explicit EnumTypeInfoTemplated(const string &enum_name_p, const vector<string> &values_insert_order_p)
41662
- : EnumTypeInfo(enum_name_p, values_insert_order_p) {
41663
- idx_t count = 0;
41664
- for (auto &value : values_insert_order) {
41665
- values[value] = count++;
41739
+ explicit EnumTypeInfoTemplated(const string &enum_name_p, Vector &values_insert_order_p, idx_t size_p)
41740
+ : EnumTypeInfo(enum_name_p, values_insert_order_p, size_p) {
41741
+ for (idx_t count = 0; count < size_p; count++) {
41742
+ values[values_insert_order_p.GetValue(count).ToString()] = count;
41666
41743
  }
41667
41744
  }
41668
- static shared_ptr<EnumTypeInfoTemplated> Deserialize(Deserializer &source) {
41745
+ static shared_ptr<EnumTypeInfoTemplated> Deserialize(Deserializer &source, uint32_t size) {
41669
41746
  auto enum_name = source.Read<string>();
41670
- vector<string> values_insert_order;
41671
- source.ReadStringVector(values_insert_order);
41672
- return make_shared<EnumTypeInfoTemplated>(move(enum_name), move(values_insert_order));
41747
+ Vector values_insert_order(LogicalType::VARCHAR, size);
41748
+ values_insert_order.Deserialize(size, source);
41749
+ return make_shared<EnumTypeInfoTemplated>(move(enum_name), values_insert_order, size);
41673
41750
  }
41674
41751
  unordered_map<string, T> values;
41675
41752
  };
@@ -41681,20 +41758,19 @@ const string &EnumType::GetTypeName(const LogicalType &type) {
41681
41758
  return ((EnumTypeInfo &)*info).enum_name;
41682
41759
  }
41683
41760
 
41684
- LogicalType LogicalType::ENUM(const string &enum_name, const vector<string> &ordered_data) {
41685
- auto size = ordered_data.size();
41761
+ LogicalType LogicalType::ENUM(const string &enum_name, Vector &ordered_data, idx_t size) {
41686
41762
  // Generate EnumTypeInfo
41687
41763
  shared_ptr<ExtraTypeInfo> info;
41688
41764
  auto enum_internal_type = EnumType::GetPhysicalType(size);
41689
41765
  switch (enum_internal_type) {
41690
41766
  case PhysicalType::UINT8:
41691
- info = make_shared<EnumTypeInfoTemplated<uint8_t>>(enum_name, ordered_data);
41767
+ info = make_shared<EnumTypeInfoTemplated<uint8_t>>(enum_name, ordered_data, size);
41692
41768
  break;
41693
41769
  case PhysicalType::UINT16:
41694
- info = make_shared<EnumTypeInfoTemplated<uint16_t>>(enum_name, ordered_data);
41770
+ info = make_shared<EnumTypeInfoTemplated<uint16_t>>(enum_name, ordered_data, size);
41695
41771
  break;
41696
41772
  case PhysicalType::UINT32:
41697
- info = make_shared<EnumTypeInfoTemplated<uint32_t>>(enum_name, ordered_data);
41773
+ info = make_shared<EnumTypeInfoTemplated<uint32_t>>(enum_name, ordered_data, size);
41698
41774
  break;
41699
41775
  default:
41700
41776
  throw InternalException("Invalid Physical Type for ENUMs");
@@ -41725,22 +41801,22 @@ int64_t EnumType::GetPos(const LogicalType &type, const string &key) {
41725
41801
  }
41726
41802
  }
41727
41803
 
41728
- const string &EnumType::GetValue(const Value &val) {
41804
+ const string EnumType::GetValue(const Value &val) {
41729
41805
  auto info = val.type().AuxInfo();
41730
- vector<string> &values_insert_order = ((EnumTypeInfo &)*info).values_insert_order;
41806
+ auto &values_insert_order = ((EnumTypeInfo &)*info).values_insert_order;
41731
41807
  switch (val.type().InternalType()) {
41732
41808
  case PhysicalType::UINT8:
41733
- return values_insert_order[val.value_.utinyint];
41809
+ return values_insert_order.GetValue(val.value_.utinyint).ToString();
41734
41810
  case PhysicalType::UINT16:
41735
- return values_insert_order[val.value_.usmallint];
41811
+ return values_insert_order.GetValue(val.value_.usmallint).ToString();
41736
41812
  case PhysicalType::UINT32:
41737
- return values_insert_order[val.value_.uinteger];
41813
+ return values_insert_order.GetValue(val.value_.uinteger).ToString();
41738
41814
  default:
41739
41815
  throw InternalException("Invalid Internal Type for ENUMs");
41740
41816
  }
41741
41817
  }
41742
41818
 
41743
- const vector<string> &EnumType::GetValuesInsertOrder(const LogicalType &type) {
41819
+ Vector &EnumType::GetValuesInsertOrder(const LogicalType &type) {
41744
41820
  D_ASSERT(type.id() == LogicalTypeId::ENUM);
41745
41821
  auto info = type.AuxInfo();
41746
41822
  D_ASSERT(info);
@@ -41751,7 +41827,7 @@ idx_t EnumType::GetSize(const LogicalType &type) {
41751
41827
  D_ASSERT(type.id() == LogicalTypeId::ENUM);
41752
41828
  auto info = type.AuxInfo();
41753
41829
  D_ASSERT(info);
41754
- return ((EnumTypeInfo &)*info).values_insert_order.size();
41830
+ return ((EnumTypeInfo &)*info).size;
41755
41831
  }
41756
41832
 
41757
41833
  void EnumType::SetCatalog(LogicalType &type, TypeCatalogEntry *catalog_entry) {
@@ -41806,14 +41882,15 @@ shared_ptr<ExtraTypeInfo> ExtraTypeInfo::Deserialize(Deserializer &source) {
41806
41882
  case ExtraTypeInfoType::USER_TYPE_INFO:
41807
41883
  return UserTypeInfo::Deserialize(source);
41808
41884
  case ExtraTypeInfoType::ENUM_TYPE_INFO: {
41809
- auto enum_internal_type = EnumType::GetPhysicalType(source.Read<uint32_t>());
41885
+ auto enum_size = source.Read<uint32_t>();
41886
+ auto enum_internal_type = EnumType::GetPhysicalType(enum_size);
41810
41887
  switch (enum_internal_type) {
41811
41888
  case PhysicalType::UINT8:
41812
- return EnumTypeInfoTemplated<uint8_t>::Deserialize(source);
41889
+ return EnumTypeInfoTemplated<uint8_t>::Deserialize(source, enum_size);
41813
41890
  case PhysicalType::UINT16:
41814
- return EnumTypeInfoTemplated<uint16_t>::Deserialize(source);
41891
+ return EnumTypeInfoTemplated<uint16_t>::Deserialize(source, enum_size);
41815
41892
  case PhysicalType::UINT32:
41816
- return EnumTypeInfoTemplated<uint32_t>::Deserialize(source);
41893
+ return EnumTypeInfoTemplated<uint32_t>::Deserialize(source, enum_size);
41817
41894
  default:
41818
41895
  throw InternalException("Invalid Physical Type for ENUMs");
41819
41896
  }
@@ -44933,7 +45010,9 @@ void FillEnum(Vector &source, Vector &result, idx_t count) {
44933
45010
 
44934
45011
  result.SetVectorType(VectorType::FLAT_VECTOR);
44935
45012
 
44936
- auto str_vec = EnumType::GetValuesInsertOrder(source.GetType());
45013
+ auto &str_vec = EnumType::GetValuesInsertOrder(source.GetType());
45014
+ auto str_vec_ptr = FlatVector::GetData<string_t>(str_vec);
45015
+
44937
45016
  auto res_enum_type = result.GetType();
44938
45017
 
44939
45018
  VectorData vdata;
@@ -44952,7 +45031,7 @@ void FillEnum(Vector &source, Vector &result, idx_t count) {
44952
45031
  result_mask.SetInvalid(i);
44953
45032
  continue;
44954
45033
  }
44955
- auto str = str_vec[source_data[src_idx]];
45034
+ auto str = str_vec_ptr[source_data[src_idx]].GetString();
44956
45035
  auto key = EnumType::GetPos(res_enum_type, str);
44957
45036
  if (key == -1) {
44958
45037
  // key doesn't exist on result enum
@@ -44986,13 +45065,17 @@ void EnumToVarchar(Vector &source, Vector &result, idx_t count, PhysicalType enu
44986
45065
  } else {
44987
45066
  result.SetVectorType(VectorType::FLAT_VECTOR);
44988
45067
  }
45068
+ auto &str_vec = EnumType::GetValuesInsertOrder(source.GetType());
45069
+ auto str_vec_ptr = FlatVector::GetData<string_t>(str_vec);
45070
+ auto res_vec_ptr = FlatVector::GetData<string_t>(result);
45071
+
44989
45072
  for (idx_t i = 0; i < count; i++) {
44990
45073
  auto src_val = source.GetValue(i);
44991
45074
  if (src_val.is_null) {
44992
45075
  result.SetValue(i, Value());
44993
45076
  continue;
44994
45077
  }
44995
- auto str_vec = EnumType::GetValuesInsertOrder(source.GetType());
45078
+
44996
45079
  uint64_t enum_idx;
44997
45080
  switch (enum_physical_type) {
44998
45081
  case PhysicalType::UINT8:
@@ -45007,7 +45090,7 @@ void EnumToVarchar(Vector &source, Vector &result, idx_t count, PhysicalType enu
45007
45090
  default:
45008
45091
  throw InternalException("ENUM can only have unsigned integers (except UINT64) as physical types");
45009
45092
  }
45010
- result.SetValue(i, Value(str_vec[enum_idx]));
45093
+ res_vec_ptr[i] = str_vec_ptr[enum_idx];
45011
45094
  }
45012
45095
  }
45013
45096
 
@@ -97988,21 +98071,26 @@ static vector<TestType> GetTestTypes() {
97988
98071
  Value("\\x00\\x00\\x00a"));
97989
98072
 
97990
98073
  // enums
97991
- vector<string> small_enum {"DUCK_DUCK_ENUM", "GOOSE"};
97992
- result.emplace_back(LogicalType::ENUM("small_enum", small_enum), "small_enum");
97993
-
97994
- vector<string> medium_enum;
98074
+ Vector small_enum(LogicalType::VARCHAR, 2);
98075
+ auto small_enum_ptr = FlatVector::GetData<string_t>(small_enum);
98076
+ small_enum_ptr[0] = StringVector::AddStringOrBlob(small_enum, "DUCK_DUCK_ENUM");
98077
+ small_enum_ptr[1] = StringVector::AddStringOrBlob(small_enum, "GOOSE");
98078
+ result.emplace_back(LogicalType::ENUM("small_enum", small_enum, 2), "small_enum");
98079
+
98080
+ Vector medium_enum(LogicalType::VARCHAR, 300);
98081
+ auto medium_enum_ptr = FlatVector::GetData<string_t>(medium_enum);
97995
98082
  for (idx_t i = 0; i < 300; i++) {
97996
- medium_enum.push_back(string("enum_") + to_string(i));
98083
+ medium_enum_ptr[i] = StringVector::AddStringOrBlob(medium_enum, string("enum_") + to_string(i));
97997
98084
  }
97998
- result.emplace_back(LogicalType::ENUM("medium_enum", medium_enum), "medium_enum");
98085
+ result.emplace_back(LogicalType::ENUM("medium_enum", medium_enum, 300), "medium_enum");
97999
98086
 
98000
98087
  // this is a big one... not sure if we should push this one here, but it's required for completeness
98001
- vector<string> large_enum;
98088
+ Vector large_enum(LogicalType::VARCHAR, 70000);
98089
+ auto large_enum_ptr = FlatVector::GetData<string_t>(large_enum);
98002
98090
  for (idx_t i = 0; i < 70000; i++) {
98003
- large_enum.push_back(string("enum_") + to_string(i));
98091
+ large_enum_ptr[i] = StringVector::AddStringOrBlob(large_enum, string("enum_") + to_string(i));
98004
98092
  }
98005
- result.emplace_back(LogicalType::ENUM("large_enum", large_enum), "large_enum");
98093
+ result.emplace_back(LogicalType::ENUM("large_enum", large_enum, 70000), "large_enum");
98006
98094
 
98007
98095
  // arrays
98008
98096
  auto int_list_type = LogicalType::LIST(LogicalType::INTEGER);
@@ -112024,6 +112112,7 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
112024
112112
  case LogicalTypeId::DOUBLE:
112025
112113
  child.format = "g";
112026
112114
  break;
112115
+ case LogicalTypeId::UUID:
112027
112116
  case LogicalTypeId::VARCHAR:
112028
112117
  child.format = "u";
112029
112118
  break;
@@ -112118,6 +112207,29 @@ void SetArrowFormat(DuckDBArrowSchemaHolder &root_holder, ArrowSchema &child, co
112118
112207
  SetArrowMapFormat(root_holder, child, type);
112119
112208
  break;
112120
112209
  }
112210
+ case LogicalTypeId::ENUM: {
112211
+ switch (EnumType::GetPhysicalType(EnumType::GetSize(type))) {
112212
+ case PhysicalType::UINT8:
112213
+ child.format = "C";
112214
+ break;
112215
+ case PhysicalType::UINT16:
112216
+ child.format = "S";
112217
+ break;
112218
+ case PhysicalType::UINT32:
112219
+ child.format = "I";
112220
+ break;
112221
+ default:
112222
+ throw InternalException("Unsupported Enum Internal Type");
112223
+ }
112224
+ root_holder.nested_children.emplace_back();
112225
+ root_holder.nested_children.back().resize(1);
112226
+ root_holder.nested_children_ptr.emplace_back();
112227
+ root_holder.nested_children_ptr.back().push_back(&root_holder.nested_children.back()[0]);
112228
+ InitializeChild(root_holder.nested_children.back()[0]);
112229
+ child.dictionary = root_holder.nested_children_ptr.back()[0];
112230
+ child.dictionary->format = "u";
112231
+ break;
112232
+ }
112121
112233
  default:
112122
112234
  throw InternalException("Unsupported Arrow type " + type.ToString());
112123
112235
  }
@@ -121868,8 +121980,11 @@ bool AreMatchesPossible(LogicalType &left, LogicalType &right) {
121868
121980
  small_enum = &right;
121869
121981
  big_enum = &left;
121870
121982
  }
121871
- auto string_vec = EnumType::GetValuesInsertOrder(*small_enum);
121872
- for (auto &key : string_vec) {
121983
+ auto &string_vec = EnumType::GetValuesInsertOrder(*small_enum);
121984
+ auto string_vec_ptr = FlatVector::GetData<string_t>(string_vec);
121985
+ auto size = EnumType::GetSize(*small_enum);
121986
+ for (idx_t i = 0; i < size; i++) {
121987
+ auto key = string_vec_ptr[i].GetString();
121873
121988
  if (EnumType::GetPos(*big_enum, key) != -1) {
121874
121989
  return true;
121875
121990
  }
@@ -142594,6 +142709,7 @@ unique_ptr<CopyStatement> Transformer::TransformCopy(duckdb_libpgquery::PGNode *
142594
142709
 
142595
142710
 
142596
142711
 
142712
+
142597
142713
  namespace duckdb {
142598
142714
 
142599
142715
  vector<string> ReadPgListToString(duckdb_libpgquery::PGList *column_list) {
@@ -142608,14 +142724,36 @@ vector<string> ReadPgListToString(duckdb_libpgquery::PGList *column_list) {
142608
142724
  return result;
142609
142725
  }
142610
142726
 
142727
+ Vector ReadPgListToVector(duckdb_libpgquery::PGList *column_list, idx_t &size) {
142728
+ if (!column_list) {
142729
+ Vector result(LogicalType::VARCHAR);
142730
+ return result;
142731
+ }
142732
+ // First we discover the size of this list
142733
+ for (auto c = column_list->head; c != nullptr; c = lnext(c)) {
142734
+ size++;
142735
+ }
142736
+
142737
+ Vector result(LogicalType::VARCHAR, size);
142738
+ auto result_ptr = FlatVector::GetData<string_t>(result);
142739
+
142740
+ size = 0;
142741
+ for (auto c = column_list->head; c != nullptr; c = lnext(c)) {
142742
+ auto target = (duckdb_libpgquery::PGResTarget *)(c->data.ptr_value);
142743
+ result_ptr[size++] = StringVector::AddStringOrBlob(result, target->name);
142744
+ }
142745
+ return result;
142746
+ }
142747
+
142611
142748
  unique_ptr<CreateStatement> Transformer::TransformCreateEnum(duckdb_libpgquery::PGNode *node) {
142612
142749
  auto stmt = reinterpret_cast<duckdb_libpgquery::PGCreateEnumStmt *>(node);
142613
142750
  D_ASSERT(stmt);
142614
142751
  auto result = make_unique<CreateStatement>();
142615
142752
  auto info = make_unique<CreateTypeInfo>();
142616
142753
  info->name = ReadPgListToString(stmt->typeName)[0];
142617
- vector<string> ordered_array = ReadPgListToString(stmt->vals);
142618
- info->type = make_unique<LogicalType>(LogicalType::ENUM(info->name, ordered_array));
142754
+ idx_t size = 0;
142755
+ auto ordered_array = ReadPgListToVector(stmt->vals, size);
142756
+ info->type = make_unique<LogicalType>(LogicalType::ENUM(info->name, ordered_array, size));
142619
142757
  result->info = move(info);
142620
142758
  return result;
142621
142759
  }
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "3c1a9e3b7"
14
- #define DUCKDB_VERSION "0.3.2-dev556"
13
+ #define DUCKDB_SOURCE_ID "087857ce5"
14
+ #define DUCKDB_VERSION "0.3.2-dev581"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -586,6 +586,7 @@ class Serializer;
586
586
  class Deserializer;
587
587
  class Value;
588
588
  class TypeCatalogEntry;
589
+ class Vector;
589
590
  //! Type used to represent dates (days since 1970-01-01)
590
591
  struct date_t {
591
592
  int32_t days;
@@ -1040,7 +1041,7 @@ public:
1040
1041
  DUCKDB_API static LogicalType STRUCT( child_list_t<LogicalType> children); // NOLINT
1041
1042
  DUCKDB_API static LogicalType MAP( child_list_t<LogicalType> children); // NOLINT
1042
1043
  DUCKDB_API static LogicalType MAP(LogicalType key, LogicalType value); // NOLINT
1043
- DUCKDB_API static LogicalType ENUM(const string &enum_name, const vector<string> &ordered_data); // NOLINT
1044
+ DUCKDB_API static LogicalType ENUM(const string &enum_name, Vector &ordered_data, idx_t size); // NOLINT
1044
1045
  DUCKDB_API static LogicalType USER(const string &user_type_name); // NOLINT
1045
1046
  //! A list of all NUMERIC types (integral and floating point types)
1046
1047
  DUCKDB_API static const vector<LogicalType> NUMERIC;
@@ -1070,9 +1071,9 @@ struct UserType{
1070
1071
  struct EnumType{
1071
1072
  DUCKDB_API static const string &GetTypeName(const LogicalType &type);
1072
1073
  DUCKDB_API static int64_t GetPos(const LogicalType &type, const string& key);
1073
- DUCKDB_API static const vector<string> &GetValuesInsertOrder(const LogicalType &type);
1074
+ DUCKDB_API static Vector &GetValuesInsertOrder(const LogicalType &type);
1074
1075
  DUCKDB_API static idx_t GetSize(const LogicalType &type);
1075
- DUCKDB_API static const string& GetValue(const Value &val);
1076
+ DUCKDB_API static const string GetValue(const Value &val);
1076
1077
  DUCKDB_API static void SetCatalog(LogicalType &type, TypeCatalogEntry* catalog_entry);
1077
1078
  DUCKDB_API static TypeCatalogEntry* GetCatalog(const LogicalType &type);
1078
1079
  DUCKDB_API static PhysicalType GetPhysicalType(idx_t size);
@@ -11782,6 +11783,7 @@ namespace duckdb {
11782
11783
  //! The UUID class contains static operations for the UUID type
11783
11784
  class UUID {
11784
11785
  public:
11786
+ constexpr static const uint8_t STRING_SIZE = 36;
11785
11787
  //! Convert a uuid string to a hugeint object
11786
11788
  static bool FromString(string str, hugeint_t &result);
11787
11789
  //! Convert a uuid string to a hugeint object
@@ -11793,9 +11795,9 @@ public:
11793
11795
 
11794
11796
  //! Convert a hugeint object to a uuid style string
11795
11797
  static string ToString(hugeint_t input) {
11796
- char buff[36];
11798
+ char buff[STRING_SIZE];
11797
11799
  ToString(input, buff);
11798
- return string(buff, 36);
11800
+ return string(buff, STRING_SIZE);
11799
11801
  }
11800
11802
 
11801
11803
  static hugeint_t FromString(string str) {