-
Notifications
You must be signed in to change notification settings - Fork 179
/
array_schema.cc
828 lines (681 loc) · 23.3 KB
/
array_schema.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/**
* @file array_schema.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2017-2021 TileDB, Inc.
* @copyright Copyright (c) 2016 MIT and Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file implements the ArraySchema class.
*/
#include "tiledb/sm/array_schema/array_schema.h"
#include "tiledb/common/heap_memory.h"
#include "tiledb/common/logger.h"
#include "tiledb/sm/array_schema/attribute.h"
#include "tiledb/sm/array_schema/dimension.h"
#include "tiledb/sm/array_schema/domain.h"
#include "tiledb/sm/buffer/const_buffer.h"
#include "tiledb/sm/enums/array_type.h"
#include "tiledb/sm/enums/compressor.h"
#include "tiledb/sm/enums/datatype.h"
#include "tiledb/sm/enums/filter_type.h"
#include "tiledb/sm/enums/layout.h"
#include "tiledb/sm/filter/compression_filter.h"
#include "tiledb/sm/misc/hilbert.h"
#include <cassert>
#include <iostream>
#include <set>
#include <sstream>
using namespace tiledb::common;
namespace tiledb {
namespace sm {
/* ****************************** */
/* CONSTRUCTORS & DESTRUCTORS */
/* ****************************** */
ArraySchema::ArraySchema()
: ArraySchema(ArrayType::DENSE) {
}
ArraySchema::ArraySchema(ArrayType array_type)
: array_type_(array_type) {
allows_dups_ = false;
array_uri_ = URI();
uri_ = URI();
name_ = "";
capacity_ = constants::capacity;
cell_order_ = Layout::ROW_MAJOR;
domain_ = nullptr;
tile_order_ = Layout::ROW_MAJOR;
version_ = constants::format_version;
auto timestamp = utils::time::timestamp_now_ms();
timestamp_range_ = std::make_pair(timestamp, timestamp);
// Set up default filter pipelines for coords, offsets, and validity values.
coords_filters_.add_filter(CompressionFilter(
constants::coords_compression, constants::coords_compression_level));
cell_var_offsets_filters_.add_filter(CompressionFilter(
constants::cell_var_offsets_compression,
constants::cell_var_offsets_compression_level));
cell_validity_filters_.add_filter(CompressionFilter(
constants::cell_validity_compression,
constants::cell_validity_compression_level));
}
ArraySchema::ArraySchema(const ArraySchema* array_schema) {
allows_dups_ = array_schema->allows_dups_;
array_uri_ = array_schema->array_uri_;
uri_ = array_schema->uri_;
name_ = array_schema->name_;
array_type_ = array_schema->array_type_;
domain_ = nullptr;
timestamp_range_ = array_schema->timestamp_range_;
capacity_ = array_schema->capacity_;
cell_order_ = array_schema->cell_order_;
cell_var_offsets_filters_ = array_schema->cell_var_offsets_filters_;
cell_validity_filters_ = array_schema->cell_validity_filters_;
coords_filters_ = array_schema->coords_filters_;
tile_order_ = array_schema->tile_order_;
version_ = array_schema->version_;
set_domain(array_schema->domain_);
attribute_map_.clear();
for (auto attr : array_schema->attributes_)
add_attribute(attr, false);
}
ArraySchema::~ArraySchema() {
clear();
}
/* ****************************** */
/* API */
/* ****************************** */
bool ArraySchema::allows_dups() const {
return allows_dups_;
}
ArrayType ArraySchema::array_type() const {
return array_type_;
}
const URI& ArraySchema::array_uri() const {
return array_uri_;
}
const Attribute* ArraySchema::attribute(unsigned int id) const {
if (id < attributes_.size())
return attributes_[id];
return nullptr;
}
const Attribute* ArraySchema::attribute(const std::string& name) const {
auto it = attribute_map_.find(name);
return it == attribute_map_.end() ? nullptr : it->second;
}
unsigned int ArraySchema::attribute_num() const {
return (unsigned)attributes_.size();
}
const std::vector<Attribute*>& ArraySchema::attributes() const {
return attributes_;
}
uint64_t ArraySchema::capacity() const {
return capacity_;
}
Layout ArraySchema::cell_order() const {
return cell_order_;
}
uint64_t ArraySchema::cell_size(const std::string& name) const {
// Special zipped coordinates attribute
if (name == constants::coords) {
auto dim_num = domain_->dim_num();
assert(dim_num > 0);
auto coord_size = domain_->dimension(0)->coord_size();
return dim_num * coord_size;
}
// Attribute
auto attr_it = attribute_map_.find(name);
if (attr_it != attribute_map_.end()) {
auto attr = attr_it->second;
auto cell_val_num = attr->cell_val_num();
return (cell_val_num == constants::var_num) ?
constants::var_size :
cell_val_num * datatype_size(attr->type());
}
// Dimension
auto dim_it = dim_map_.find(name);
assert(dim_it != dim_map_.end());
auto dim = dim_it->second;
auto cell_val_num = dim->cell_val_num();
return (cell_val_num == constants::var_num) ?
constants::var_size :
cell_val_num * datatype_size(dim->type());
}
unsigned int ArraySchema::cell_val_num(const std::string& name) const {
// Special zipped coordinates
if (name == constants::coords)
return 1;
// Attribute
auto attr_it = attribute_map_.find(name);
if (attr_it != attribute_map_.end())
return attr_it->second->cell_val_num();
// Dimension
auto dim_it = dim_map_.find(name);
assert(dim_it != dim_map_.end());
return dim_it->second->cell_val_num();
}
const FilterPipeline& ArraySchema::cell_var_offsets_filters() const {
return cell_var_offsets_filters_;
}
const FilterPipeline& ArraySchema::cell_validity_filters() const {
return cell_validity_filters_;
}
Status ArraySchema::check() const {
if (domain_ == nullptr)
return LOG_STATUS(
Status::ArraySchemaError("Array schema check failed; Domain not set"));
auto dim_num = this->dim_num();
if (dim_num == 0)
return LOG_STATUS(Status::ArraySchemaError(
"Array schema check failed; No dimensions provided"));
if (cell_order_ == Layout::HILBERT && dim_num > Hilbert::HC_MAX_DIM) {
return LOG_STATUS(Status::ArraySchemaError(
"Array schema check failed; Maximum dimensions supported by Hilbert "
"order exceeded"));
}
if (array_type_ == ArrayType::DENSE) {
auto type = domain_->dimension(0)->type();
if (datatype_is_real(type)) {
return LOG_STATUS(
Status::ArraySchemaError("Array schema check failed; Dense arrays "
"cannot have floating point domains"));
}
if (attributes_.size() == 0) {
return LOG_STATUS(Status::ArraySchemaError(
"Array schema check failed; No attributes provided"));
}
}
RETURN_NOT_OK(check_double_delta_compressor());
if (!check_attribute_dimension_names())
return LOG_STATUS(
Status::ArraySchemaError("Array schema check failed; Attributes "
"and dimensions must have unique names"));
// Success
return Status::Ok();
}
Status ArraySchema::check_attributes(
const std::vector<std::string>& attributes) const {
for (const auto& attr : attributes) {
if (attr == constants::coords)
continue;
if (attribute_map_.find(attr) == attribute_map_.end())
return LOG_STATUS(Status::ArraySchemaError(
"Attribute check failed; cannot find attribute"));
}
return Status::Ok();
}
const FilterPipeline& ArraySchema::filters(const std::string& name) const {
if (name == constants::coords)
return coords_filters();
// Attribute
auto attr_it = attribute_map_.find(name);
if (attr_it != attribute_map_.end())
return attr_it->second->filters();
// Dimension (if filters not set, return default coordinate filters)
auto dim_it = dim_map_.find(name);
assert(dim_it != dim_map_.end());
const auto& ret = dim_it->second->filters();
return !ret.empty() ? ret : coords_filters();
}
const FilterPipeline& ArraySchema::coords_filters() const {
return coords_filters_;
}
bool ArraySchema::dense() const {
return array_type_ == ArrayType::DENSE;
}
const Dimension* ArraySchema::dimension(unsigned int i) const {
return domain_->dimension(i);
}
const Dimension* ArraySchema::dimension(const std::string& name) const {
auto it = dim_map_.find(name);
return it == dim_map_.end() ? nullptr : it->second;
}
std::vector<std::string> ArraySchema::dim_names() const {
auto dim_num = this->dim_num();
std::vector<std::string> ret;
ret.reserve(dim_num);
for (uint32_t d = 0; d < dim_num; ++d)
ret.emplace_back(domain_->dimension(d)->name());
return ret;
}
std::vector<Datatype> ArraySchema::dim_types() const {
auto dim_num = this->dim_num();
std::vector<Datatype> ret;
ret.reserve(dim_num);
for (uint32_t d = 0; d < dim_num; ++d)
ret.emplace_back(domain_->dimension(d)->type());
return ret;
}
unsigned int ArraySchema::dim_num() const {
return domain_->dim_num();
}
void ArraySchema::dump(FILE* out) const {
if (out == nullptr)
out = stdout;
std::stringstream ss;
ss << "- Array type: " << array_type_str(array_type_) << "\n";
ss << "- Cell order: " << layout_str(cell_order_) << "\n";
ss << "- Tile order: " << layout_str(tile_order_) << "\n";
ss << "- Capacity: " << capacity_ << "\n";
ss << "- Allows duplicates: " << (allows_dups_ ? "true" : "false") << "\n";
ss << "- Coordinates filters: " << coords_filters_.size();
fprintf(out, "%s", ss.str().c_str());
coords_filters_.dump(out);
fprintf(
out,
"\n- Offsets filters: %u",
(unsigned)cell_var_offsets_filters_.size());
cell_var_offsets_filters_.dump(out);
fprintf(
out, "\n- Validity filters: %u", (unsigned)cell_validity_filters_.size());
cell_validity_filters_.dump(out);
fprintf(out, "\n");
if (domain_ != nullptr)
domain_->dump(out);
for (auto& attr : attributes_) {
fprintf(out, "\n");
attr->dump(out);
}
}
Status ArraySchema::has_attribute(
const std::string& name, bool* has_attr) const {
*has_attr = false;
for (auto& attr : attributes_) {
if (name == attr->name()) {
*has_attr = true;
break;
}
}
return Status::Ok();
}
bool ArraySchema::is_attr(const std::string& name) const {
return this->attribute(name) != nullptr;
}
bool ArraySchema::is_dim(const std::string& name) const {
return this->dimension(name) != nullptr;
}
bool ArraySchema::is_nullable(const std::string& name) const {
const Attribute* const attr = this->attribute(name);
if (attr == nullptr)
return false;
return attr->nullable();
}
// ===== FORMAT =====
// version (uint32_t)
// allow_dups (bool)
// array_type (uint8_t)
// tile_order (uint8_t)
// cell_order (uint8_t)
// capacity (uint64_t)
// coords_filters (see FilterPipeline::serialize)
// cell_var_offsets_filters (see FilterPipeline::serialize)
// cell_validity_filters (see FilterPipeline::serialize)
// domain
// attribute_num (uint32_t)
// attribute #1
// attribute #2
// ...
Status ArraySchema::serialize(Buffer* buff) const {
// Write version, which is always the current version. Despite
// the in-memory `version_`, we will serialize every array schema
// as the latest version.
const uint32_t version = constants::format_version;
RETURN_NOT_OK(buff->write(&version, sizeof(uint32_t)));
// Write allows_dups
RETURN_NOT_OK(buff->write(&allows_dups_, sizeof(bool)));
// Write array type
auto array_type = (uint8_t)array_type_;
RETURN_NOT_OK(buff->write(&array_type, sizeof(uint8_t)));
// Write tile and cell order
auto tile_order = (uint8_t)tile_order_;
RETURN_NOT_OK(buff->write(&tile_order, sizeof(uint8_t)));
auto cell_order = (uint8_t)cell_order_;
RETURN_NOT_OK(buff->write(&cell_order, sizeof(uint8_t)));
// Write capacity
RETURN_NOT_OK(buff->write(&capacity_, sizeof(uint64_t)));
// Write coords filters
RETURN_NOT_OK(coords_filters_.serialize(buff));
// Write offsets filters
RETURN_NOT_OK(cell_var_offsets_filters_.serialize(buff));
// Write validity filters
RETURN_NOT_OK(cell_validity_filters_.serialize(buff));
// Write domain
RETURN_NOT_OK(domain_->serialize(buff, version));
// Write attributes
auto attribute_num = (uint32_t)attributes_.size();
RETURN_NOT_OK(buff->write(&attribute_num, sizeof(uint32_t)));
for (auto& attr : attributes_)
RETURN_NOT_OK(attr->serialize(buff, version));
return Status::Ok();
}
Layout ArraySchema::tile_order() const {
return tile_order_;
}
Datatype ArraySchema::type(const std::string& name) const {
// Special zipped coordinates attribute
if (name == constants::coords)
return domain_->dimension(0)->type();
// Attribute
auto attr_it = attribute_map_.find(name);
if (attr_it != attribute_map_.end())
return attr_it->second->type();
// Dimension
auto dim_it = dim_map_.find(name);
assert(dim_it != dim_map_.end());
return dim_it->second->type();
}
bool ArraySchema::var_size(const std::string& name) const {
// Special case for zipped coordinates
if (name == constants::coords)
return false;
// Attribute
auto attr_it = attribute_map_.find(name);
if (attr_it != attribute_map_.end())
return attr_it->second->var_size();
// Dimension
auto dim_it = dim_map_.find(name);
if (dim_it != dim_map_.end())
return dim_it->second->var_size();
// Name is not an attribute or dimension
assert(false);
return false;
}
Status ArraySchema::add_attribute(const Attribute* attr, bool check_special) {
// Sanity check
if (attr == nullptr)
return LOG_STATUS(Status::ArraySchemaError(
"Cannot add attribute; Input attribute is null"));
// Do not allow attributes with special names
if (check_special && attr->name().find(constants::special_name_prefix) == 0) {
std::string msg = "Cannot add attribute; Attribute names starting with '";
msg += std::string(constants::special_name_prefix) + "' are reserved";
return LOG_STATUS(Status::ArraySchemaError(msg));
}
// Create new attribute and potentially set a default name
auto new_attr = tdb_new(Attribute, attr);
attributes_.emplace_back(new_attr);
attribute_map_[new_attr->name()] = new_attr;
return Status::Ok();
}
Status ArraySchema::deserialize(ConstBuffer* buff) {
// Load version
RETURN_NOT_OK(buff->read(&version_, sizeof(uint32_t)));
// Load allows_dups
if (version_ >= 5)
RETURN_NOT_OK(buff->read(&allows_dups_, sizeof(bool)));
// Load array type
uint8_t array_type;
RETURN_NOT_OK(buff->read(&array_type, sizeof(uint8_t)));
array_type_ = (ArrayType)array_type;
// Load tile order
uint8_t tile_order;
RETURN_NOT_OK(buff->read(&tile_order, sizeof(uint8_t)));
tile_order_ = (Layout)tile_order;
// Load cell order
uint8_t cell_order;
RETURN_NOT_OK(buff->read(&cell_order, sizeof(uint8_t)));
cell_order_ = (Layout)cell_order;
// Load capacity
RETURN_NOT_OK(buff->read(&capacity_, sizeof(uint64_t)));
// Load coords filters
RETURN_NOT_OK(coords_filters_.deserialize(buff));
// Load offsets filters
RETURN_NOT_OK(cell_var_offsets_filters_.deserialize(buff));
// Load validity filters
if (version_ >= 7)
RETURN_NOT_OK(cell_validity_filters_.deserialize(buff));
// Load domain
domain_ = tdb_new(Domain);
RETURN_NOT_OK(domain_->deserialize(buff, version_));
// Load attributes
uint32_t attribute_num;
RETURN_NOT_OK(buff->read(&attribute_num, sizeof(uint32_t)));
for (uint32_t i = 0; i < attribute_num; ++i) {
auto attr = tdb_new(Attribute);
RETURN_NOT_OK_ELSE(attr->deserialize(buff, version_), tdb_delete(attr));
attributes_.emplace_back(attr);
attribute_map_[attr->name()] = attr;
}
// Create dimension map
auto dim_num = domain()->dim_num();
for (unsigned d = 0; d < dim_num; ++d) {
auto dim = dimension(d);
dim_map_[dim->name()] = dim;
}
// Initialize the rest of the object members
RETURN_NOT_OK(init());
// Success
return Status::Ok();
}
const Domain* ArraySchema::domain() const {
return domain_;
}
Status ArraySchema::init() {
// Perform check of all members
RETURN_NOT_OK(check());
// Initialize domain
RETURN_NOT_OK(domain_->init(cell_order_, tile_order_));
// Success
return Status::Ok();
}
Status ArraySchema::set_allows_dups(bool allows_dups) {
if (allows_dups && array_type_ == ArrayType::DENSE)
return LOG_STATUS(Status::ArraySchemaError(
"Dense arrays cannot allow coordinate duplicates"));
allows_dups_ = allows_dups;
return Status::Ok();
}
void ArraySchema::set_array_uri(const URI& array_uri) {
array_uri_ = array_uri;
}
void ArraySchema::set_capacity(uint64_t capacity) {
capacity_ = capacity;
}
Status ArraySchema::set_coords_filter_pipeline(const FilterPipeline* pipeline) {
coords_filters_ = *pipeline;
return Status::Ok();
}
Status ArraySchema::set_cell_var_offsets_filter_pipeline(
const FilterPipeline* pipeline) {
cell_var_offsets_filters_ = *pipeline;
return Status::Ok();
}
Status ArraySchema::set_cell_order(Layout cell_order) {
if (dense() && cell_order == Layout::HILBERT)
return LOG_STATUS(
Status::ArraySchemaError("Cannot set cell order; Hilbert order is only "
"applicable to sparse arrays"));
cell_order_ = cell_order;
return Status::Ok();
}
Status ArraySchema::set_cell_validity_filter_pipeline(
const FilterPipeline* pipeline) {
cell_validity_filters_ = *pipeline;
return Status::Ok();
}
Status ArraySchema::set_domain(Domain* domain) {
if (domain == nullptr)
return LOG_STATUS(
Status::ArraySchemaError("Cannot set domain; Input domain is nullptr"));
if (domain->dim_num() == 0)
return LOG_STATUS(Status::ArraySchemaError(
"Cannot set domain; Domain must contain at least one dimension"));
if (array_type_ == ArrayType::DENSE) {
if (!domain->all_dims_same_type())
return LOG_STATUS(
Status::ArraySchemaError("Cannot set domain; In dense arrays, all "
"dimensions must have the same datatype"));
auto type = domain->dimension(0)->type();
if (!datatype_is_integer(type) && !datatype_is_datetime(type) &&
!datatype_is_time(type)) {
return LOG_STATUS(Status::ArraySchemaError(
std::string("Cannot set domain; Dense arrays "
"do not support dimension datatype '") +
datatype_str(type) + "'"));
}
}
if (cell_order_ != Layout::HILBERT) {
RETURN_NOT_OK(domain->set_null_tile_extents_to_range());
}
// Set domain
tdb_delete(domain_);
domain_ = tdb_new(Domain, domain);
// Create dimension map
dim_map_.clear();
auto dim_num = domain_->dim_num();
for (unsigned d = 0; d < dim_num; ++d) {
auto dim = dimension(d);
dim_map_[dim->name()] = dim;
}
return Status::Ok();
}
Status ArraySchema::set_tile_order(Layout tile_order) {
if (tile_order == Layout::HILBERT)
return LOG_STATUS(Status::ArraySchemaError(
"Cannot set tile order; Hilbert order is not applicable to tiles"));
tile_order_ = tile_order;
return Status::Ok();
}
void ArraySchema::set_version(uint32_t version) {
version_ = version;
}
uint32_t ArraySchema::write_version() const {
return version_ < constants::back_compat_writes_min_format_version ?
constants::format_version :
version_;
}
uint32_t ArraySchema::version() const {
return version_;
}
Status ArraySchema::set_timestamp_range(
const std::pair<uint64_t, uint64_t>& timestamp_range) {
timestamp_range_ = timestamp_range;
return Status::Ok();
}
const std::pair<uint64_t, uint64_t>& ArraySchema::timestamp_range() const {
return timestamp_range_;
}
const URI& ArraySchema::uri() {
std::lock_guard<std::mutex> lock(mtx_);
if (uri_.is_invalid()) {
generate_uri();
}
return uri_;
}
void ArraySchema::set_uri(URI& uri) {
std::lock_guard<std::mutex> lock(mtx_);
uri_ = uri;
name_ = uri_.last_path_part();
utils::parse::get_timestamp_range(uri_, ×tamp_range_);
}
Status ArraySchema::get_uri(URI* uri) {
if (uri_.is_invalid()) {
return LOG_STATUS(
Status::ArraySchemaError("Error in ArraySchema; invalid URI"));
}
*uri = uri_;
return Status::Ok();
}
const std::string& ArraySchema::name() {
std::lock_guard<std::mutex> lock(mtx_);
if (name_.empty()) {
generate_uri();
}
return name_;
}
Status ArraySchema::get_name(std::string* name) const {
if (name_.empty()) {
return LOG_STATUS(
Status::ArraySchemaError("Error in ArraySchema; Empty name"));
}
*name = name_;
return Status::Ok();
}
/* ****************************** */
/* PRIVATE METHODS */
/* ****************************** */
bool ArraySchema::check_attribute_dimension_names() const {
std::set<std::string> names;
auto dim_num = this->dim_num();
for (auto attr : attributes_)
names.insert(attr->name());
for (unsigned int i = 0; i < dim_num; ++i)
names.insert(domain_->dimension(i)->name());
return (names.size() == attributes_.size() + dim_num);
}
Status ArraySchema::check_double_delta_compressor() const {
// Check if coordinate filters have DOUBLE DELTA as a compressor
bool has_double_delta = false;
for (unsigned i = 0; i < coords_filters_.size(); ++i) {
if (coords_filters_.get_filter(i)->type() ==
FilterType::FILTER_DOUBLE_DELTA) {
has_double_delta = true;
break;
}
}
// Not applicable when DOUBLE DELTA no present in coord filters
if (!has_double_delta)
return Status::Ok();
// Error if any real dimension inherits the coord filters with DOUBLE DELTA.
// A dimension inherits the filters when it has no filters.
auto dim_num = domain_->dim_num();
for (unsigned d = 0; d < dim_num; ++d) {
auto dim = domain_->dimension(d);
const auto& dim_filters = dim->filters();
auto dim_type = dim->type();
if (datatype_is_real(dim_type) && dim_filters.empty())
return LOG_STATUS(
Status::ArraySchemaError("Real dimension cannot inherit coordinate "
"filters with DOUBLE DELTA compression"));
}
return Status::Ok();
}
void ArraySchema::clear() {
array_uri_ = URI();
uri_ = URI();
name_.clear();
array_type_ = ArrayType::DENSE;
capacity_ = constants::capacity;
cell_order_ = Layout::ROW_MAJOR;
tile_order_ = Layout::ROW_MAJOR;
for (auto& attr : attributes_)
tdb_delete(attr);
attributes_.clear();
tdb_delete(domain_);
domain_ = nullptr;
timestamp_range_ = std::make_pair(0, 0);
}
Status ArraySchema::generate_uri() {
std::string uuid;
RETURN_NOT_OK(uuid::generate_uuid(&uuid, false));
std::stringstream ss;
ss << "__" << timestamp_range_.first << "_" << timestamp_range_.second << "_"
<< uuid;
name_ = ss.str();
uri_ = array_uri_.join_path(constants::array_schema_folder_name)
.join_path(name_);
return Status::Ok();
}
} // namespace sm
} // namespace tiledb