MCPcopy Create free account
hub / github.com/TileDB-Inc/TileDB / create_array

Method create_array

test/src/unit-capi-string.cc:80–153  ·  view source on GitHub ↗

Create a simple dense 1D array with three string attributes

Source from the content-addressed store, hash-verified

78
79// Create a simple dense 1D array with three string attributes
80void StringFx::create_array(const std::string& array_name) {
81 // Create dimensions
82 uint64_t dim_domain[] = {1, 4};
83 uint64_t tile_extent = 2;
84 tiledb_dimension_t* d1;
85 int rc = tiledb_dimension_alloc(
86 ctx_, "d1", TILEDB_UINT64, &dim_domain[0], &tile_extent, &d1);
87 REQUIRE(rc == TILEDB_OK);
88
89 // Create domain
90 tiledb_domain_t* domain;
91 rc = tiledb_domain_alloc(ctx_, &domain);
92 REQUIRE(rc == TILEDB_OK);
93 rc = tiledb_domain_add_dimension(ctx_, domain, d1);
94 REQUIRE(rc == TILEDB_OK);
95
96 // Create fixed-sized UTF-8 attribute
97 tiledb_attribute_t* a1;
98 rc = tiledb_attribute_alloc(ctx_, "a1", TILEDB_STRING_ASCII, &a1);
99 REQUIRE(rc == TILEDB_OK);
100 rc = tiledb_attribute_set_cell_val_num(ctx_, a1, 2);
101 REQUIRE(rc == TILEDB_OK);
102
103 // Create variable-sized UTF-8 attribute
104 tiledb_attribute_t* a2;
105 rc = tiledb_attribute_alloc(ctx_, "a2", TILEDB_STRING_UTF8, &a2);
106 REQUIRE(rc == TILEDB_OK);
107 rc = tiledb_attribute_set_cell_val_num(ctx_, a2, TILEDB_VAR_NUM);
108 REQUIRE(rc == TILEDB_OK);
109 rc = set_attribute_compression_filter(ctx_, a2, TILEDB_FILTER_GZIP, -1);
110 REQUIRE(rc == TILEDB_OK);
111
112 // Create variable-sized UTF-16 attribute
113 tiledb_attribute_t* a3;
114 rc = tiledb_attribute_alloc(ctx_, "a3", TILEDB_STRING_UTF16, &a3);
115 REQUIRE(rc == TILEDB_OK);
116 rc = tiledb_attribute_set_cell_val_num(ctx_, a3, TILEDB_VAR_NUM);
117 REQUIRE(rc == TILEDB_OK);
118 rc = set_attribute_compression_filter(ctx_, a3, TILEDB_FILTER_ZSTD, -1);
119 REQUIRE(rc == TILEDB_OK);
120
121 // Create array schema
122 tiledb_array_schema_t* array_schema;
123 rc = tiledb_array_schema_alloc(ctx_, TILEDB_DENSE, &array_schema);
124 REQUIRE(rc == TILEDB_OK);
125 rc = tiledb_array_schema_set_cell_order(ctx_, array_schema, TILEDB_ROW_MAJOR);
126 REQUIRE(rc == TILEDB_OK);
127 rc = tiledb_array_schema_set_tile_order(ctx_, array_schema, TILEDB_ROW_MAJOR);
128 REQUIRE(rc == TILEDB_OK);
129 rc = tiledb_array_schema_set_domain(ctx_, array_schema, domain);
130 REQUIRE(rc == TILEDB_OK);
131 rc = tiledb_array_schema_add_attribute(ctx_, array_schema, a1);
132 REQUIRE(rc == TILEDB_OK);
133 rc = tiledb_array_schema_add_attribute(ctx_, array_schema, a2);
134 REQUIRE(rc == TILEDB_OK);
135 rc = tiledb_array_schema_add_attribute(ctx_, array_schema, a3);
136 REQUIRE(rc == TILEDB_OK);
137

Callers

nothing calls this directly

Tested by

no test coverage detected