Skip to content

Commit d8a761e

Browse files
committed
Add CDvInfo struct
1 parent 5552d21 commit d8a761e

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

ffi/examples/read-table/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ include(CTest)
1414
set(TestRunner "../../../tests/read-table-testing/run_test.sh")
1515
set(DatPath "../../../../acceptance/tests/dat/out/reader_tests/generated")
1616
set(ExpectedPath "../../../tests/read-table-testing/expected-data")
17+
set(KernelTestPath "../../../../kernel/tests/data")
1718
add_test(NAME read_and_print_all_prim COMMAND ${TestRunner} ${DatPath}/all_primitive_types/delta/ ${ExpectedPath}/all-prim-types.expected)
1819
add_test(NAME read_and_print_basic_partitioned COMMAND ${TestRunner} ${DatPath}/basic_partitioned/delta/ ${ExpectedPath}/basic-partitioned.expected)
20+
add_test(NAME read_and_print_with_dv_small COMMAND ${TestRunner} ${KernelTestPath}/table-with-dv-small/ ${ExpectedPath}/table-with-dv-small.expected)
1921

2022
if(WIN32)
2123
set(CMAKE_C_FLAGS_DEBUG "/MT")

ffi/examples/read-table/read_table.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void scan_row_callback(
4949
KernelStringSlice path,
5050
int64_t size,
5151
const Stats* stats,
52-
const DvInfo* dv_info,
52+
const CDvInfo* cdv_info,
5353
const Expression* transform,
5454
const CStringMap* partition_values)
5555
{
@@ -62,18 +62,25 @@ void scan_row_callback(
6262
print_diag(" [no stats])\n");
6363
}
6464
KernelStringSlice table_root_slice = { context->table_root, strlen(context->table_root) };
65-
ExternResultKernelBoolSlice selection_vector_res =
66-
selection_vector_from_dv(dv_info, context->engine, table_root_slice);
67-
if (selection_vector_res.tag != OkKernelBoolSlice) {
68-
printf("Could not get selection vector from kernel\n");
69-
exit(-1);
70-
}
71-
KernelBoolSlice selection_vector = selection_vector_res.ok;
72-
if (selection_vector.len > 0) {
73-
print_diag(" Selection vector for this file:\n");
74-
print_selection_vector(" ", &selection_vector);
65+
KernelBoolSlice selection_vector;
66+
67+
if (cdv_info->has_vector) {
68+
ExternResultKernelBoolSlice selection_vector_res =
69+
selection_vector_from_dv(cdv_info->info, context->engine, table_root_slice);
70+
if (selection_vector_res.tag != OkKernelBoolSlice) {
71+
printf("Could not get selection vector from kernel\n");
72+
exit(-1);
73+
}
74+
selection_vector = selection_vector_res.ok;
75+
if (selection_vector.len > 0) {
76+
print_diag(" Selection vector for this file:\n");
77+
print_selection_vector(" ", &selection_vector);
78+
} else {
79+
print_diag(" No selection vector for this file\n");
80+
}
7581
} else {
7682
print_diag(" No selection vector for this file\n");
83+
selection_vector.len = 0;
7784
}
7885
context->partition_values = partition_values;
7986
print_partition_info(context, partition_values);

ffi/src/scan.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,23 @@ pub struct Stats {
275275
pub num_records: u64,
276276
}
277277

278+
/// Contains information that can be used to get a selection vector. If `has_vector` is false, that
279+
/// indicates there is no selection vector to consider. It is always possible to get a vector out of
280+
/// a `DvInfo`, but if `has_vector` is false it will just be an empty vector (indicating all
281+
/// selected).
282+
#[repr(C)]
283+
pub struct CDvInfo<'a> {
284+
info: &'a DvInfo,
285+
has_vector: bool,
286+
}
287+
278288
/// This callback will be invoked for each valid file that needs to be read for a scan.
279289
///
280290
/// The arguments to the callback are:
281291
/// * `context`: a `void*` context this can be anything that engine needs to pass through to each call
282292
/// * `path`: a `KernelStringSlice` which is the path to the file
283293
/// * `size`: an `i64` which is the size of the file
284-
/// * `dv_info`: a [`DvInfo`] struct, which allows getting the selection vector for this file
294+
/// * `dv_info`: a [`CDvInfo`] struct, which allows getting the selection vector for this file
285295
/// * `transform`: An optional expression that, if not `NULL`, _must_ be applied to physical data to
286296
/// convert it to the correct logical format. If this is `NULL`, no transform is needed.
287297
/// * `partition_values`: [DEPRECATED] a `HashMap<String, String>` which are partition values
@@ -290,7 +300,7 @@ type CScanCallback = extern "C" fn(
290300
path: KernelStringSlice,
291301
size: i64,
292302
stats: Option<&Stats>,
293-
dv_info: &DvInfo,
303+
dv_info: &CDvInfo,
294304
transform: Option<&Expression>,
295305
partition_map: &CStringMap,
296306
);
@@ -430,12 +440,16 @@ fn rust_callback(
430440
let stats = kernel_stats.map(|ks| Stats {
431441
num_records: ks.num_records,
432442
});
443+
let cdv_info = CDvInfo {
444+
info: &dv_info,
445+
has_vector: dv_info.has_vector(),
446+
};
433447
(context.callback)(
434448
context.engine_context,
435449
kernel_string_slice!(path),
436450
size,
437451
stats.as_ref(),
438-
&dv_info,
452+
&cdv_info,
439453
transform.as_ref(),
440454
&partition_map,
441455
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Reading table at ../../../../kernel/tests/data/table-with-dv-small/
2+
version: 1
3+
4+
Schema:
5+
└─ value: integer
6+
7+
value: [
8+
1,
9+
2,
10+
3,
11+
4,
12+
5,
13+
6,
14+
7,
15+
8
16+
]

0 commit comments

Comments
 (0)