| 108 | } |
| 109 | |
| 110 | void read_array_metadata() { |
| 111 | // Create TileDB context |
| 112 | tiledb_ctx_t* ctx; |
| 113 | tiledb_ctx_alloc(NULL, &ctx); |
| 114 | |
| 115 | // Open array for reading |
| 116 | tiledb_array_t* array; |
| 117 | tiledb_array_alloc(ctx, array_name, &array); |
| 118 | tiledb_array_open(ctx, array, TILEDB_READ); |
| 119 | |
| 120 | // Read with key |
| 121 | tiledb_datatype_t v_type; |
| 122 | uint32_t v_num; |
| 123 | const void* v; |
| 124 | tiledb_array_get_metadata(ctx, array, "aaa", &v_type, &v_num, &v); |
| 125 | printf("Details of item with key: '%s'\n", "aaa"); |
| 126 | printf( |
| 127 | "- Value type: %s\n", |
| 128 | (v_type == TILEDB_INT32) ? "INT32" : "something went wrong"); |
| 129 | printf("- Value num: %u\n", v_num); |
| 130 | printf("- Value: %i\n", *(const int*)v); |
| 131 | |
| 132 | tiledb_array_get_metadata(ctx, array, "bb", &v_type, &v_num, &v); |
| 133 | printf("Details of item with key: '%s'\n", "bb"); |
| 134 | printf( |
| 135 | "- Value type: %s\n", |
| 136 | (v_type == TILEDB_FLOAT32) ? "FLOAT32" : "something went wrong"); |
| 137 | printf("- Value num: %u\n", v_num); |
| 138 | printf("- Value: %f, %f\n", ((const float*)v)[0], ((const float*)v)[1]); |
| 139 | |
| 140 | // Enumerate all metadata items |
| 141 | uint64_t num = 0; |
| 142 | const char* key; |
| 143 | uint32_t key_len; |
| 144 | tiledb_array_get_metadata_num(ctx, array, &num); |
| 145 | printf("Enumerate all metadata items:\n"); |
| 146 | for (uint64_t i = 0; i < num; ++i) { |
| 147 | tiledb_array_get_metadata_from_index( |
| 148 | ctx, array, i, &key, &key_len, &v_type, &v_num, &v); |
| 149 | |
| 150 | printf("# Item %i\n", (int)i); |
| 151 | const char* v_type_str = (v_type == TILEDB_INT32) ? "INT32" : "FLOAT32"; |
| 152 | printf("- Key: %.*s\n", key_len, key); |
| 153 | printf("- Value type: %s\n", v_type_str); |
| 154 | printf("- Value num: %u\n", v_num); |
| 155 | printf("- Value: "); |
| 156 | if (v_type == TILEDB_INT32) { |
| 157 | for (uint32_t j = 0; j < v_num; ++j) |
| 158 | printf("%i ", ((const int*)v)[j]); |
| 159 | } else if (v_type == TILEDB_FLOAT32) { |
| 160 | for (uint32_t j = 0; j < v_num; ++j) |
| 161 | printf("%f ", ((const float*)v)[j]); |
| 162 | } |
| 163 | printf("\n"); |
| 164 | } |
| 165 | |
| 166 | // Close array |
| 167 | tiledb_array_close(ctx, array); |
no test coverage detected