Skip to content

Commit f87913f

Browse files
committed
Fixed carquet repetition option bugs - v0.1.3
1 parent a303659 commit f87913f

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.16)
2-
project(carquet VERSION 0.1.2 LANGUAGES C)
2+
project(carquet VERSION 0.1.3 LANGUAGES C)
33

44
set(CMAKE_C_STANDARD 11)
55
set(CMAKE_C_STANDARD_REQUIRED ON)

examples/nullable_columns.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,18 @@ static int write_nullable_data(const char* filename, carquet_schema_t* schema) {
188188
if (status != CARQUET_OK) goto error;
189189

190190
/* Write optional columns WITH definition levels */
191-
/* Note: Only non-null values are in the values array! */
192-
status = carquet_writer_write_batch(writer, 2, ages, age_value_count,
191+
/* Note: Only non-null values are in the values array, but num_values
192+
* is the total number of logical rows (including NULLs). The def_levels
193+
* array has one entry per logical row indicating null vs present. */
194+
status = carquet_writer_write_batch(writer, 2, ages, NUM_ROWS,
193195
age_def_levels, NULL);
194196
if (status != CARQUET_OK) goto error;
195197

196-
status = carquet_writer_write_batch(writer, 3, scores, score_value_count,
198+
status = carquet_writer_write_batch(writer, 3, scores, NUM_ROWS,
197199
score_def_levels, NULL);
198200
if (status != CARQUET_OK) goto error;
199201

200-
status = carquet_writer_write_batch(writer, 4, emails, email_value_count,
202+
status = carquet_writer_write_batch(writer, 4, emails, NUM_ROWS,
201203
email_def_levels, NULL);
202204
if (status != CARQUET_OK) goto error;
203205

include/carquet/carquet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file carquet.h
33
* @brief Carquet - High-Performance Pure C Parquet Library
4-
* @version 0.1.2
4+
* @version 0.1.3
55
*
66
* @copyright Copyright (c) 2025. All rights reserved.
77
* @license MIT License
@@ -196,10 +196,10 @@ extern "C" {
196196
#define CARQUET_VERSION_MINOR 1
197197

198198
/** @brief Patch version number */
199-
#define CARQUET_VERSION_PATCH 2
199+
#define CARQUET_VERSION_PATCH 3
200200

201201
/** @brief Version string in "MAJOR.MINOR.PATCH" format */
202-
#define CARQUET_VERSION_STRING "0.1.2"
202+
#define CARQUET_VERSION_STRING "0.1.3"
203203

204204
/** @brief Numeric version for compile-time comparisons: (MAJOR * 10000 + MINOR * 100 + PATCH) */
205205
#define CARQUET_VERSION_NUMBER (CARQUET_VERSION_MAJOR * 10000 + CARQUET_VERSION_MINOR * 100 + CARQUET_VERSION_PATCH)

src/writer/page_writer.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,26 @@ carquet_status_t carquet_page_writer_add_values(
307307
writer->num_nulls += (num_values - num_non_null);
308308
}
309309

310-
/* Encode definition levels */
311-
if (writer->max_def_level > 0 && def_levels) {
312-
encode_levels(def_levels, num_values, writer->max_def_level,
313-
&writer->def_levels_buffer);
310+
/* Encode definition levels.
311+
* If def_levels is NULL for an OPTIONAL column, generate all-present levels
312+
* since Parquet requires definition levels for non-REQUIRED columns. */
313+
if (writer->max_def_level > 0) {
314+
if (def_levels) {
315+
encode_levels(def_levels, num_values, writer->max_def_level,
316+
&writer->def_levels_buffer);
317+
} else {
318+
/* Auto-generate all-present definition levels */
319+
int16_t* auto_def = malloc(num_values * sizeof(int16_t));
320+
if (!auto_def) {
321+
return CARQUET_ERROR_OUT_OF_MEMORY;
322+
}
323+
for (int64_t i = 0; i < num_values; i++) {
324+
auto_def[i] = writer->max_def_level;
325+
}
326+
encode_levels(auto_def, num_values, writer->max_def_level,
327+
&writer->def_levels_buffer);
328+
free(auto_def);
329+
}
314330
}
315331

316332
/* Encode repetition levels */

0 commit comments

Comments
 (0)