Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 9e85cbb

Browse files
committed
Remove the old C-FFI POC code and add an XCTest
1 parent a610912 commit 9e85cbb

5 files changed

Lines changed: 51 additions & 26 deletions

File tree

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
#include "ParquetLogger.h"
22

3-
extern "C" {
4-
extern bool parquet2_1337_bloom_filter_contains(int64_t x);
5-
}
6-
7-
bool FilterContains(int64_t x) {
8-
return parquet2_1337_bloom_filter_contains(x);
9-
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#include <stdint.h>
1+
#include "Source/santad/Logs/EndpointSecurity/ParquetLogger/gen/cpp_api.rs.h"
22

33
#ifndef SANTA__SANTAD__LOGS_ENDPOINTSECURITY_PARQUETLOGGER_PARQUETLOGGER_H
44
#define SANTA__SANTAD__LOGS_ENDPOINTSECURITY_PARQUETLOGGER_PARQUETLOGGER_H
55

6-
bool FilterContains(int64_t x);
7-
86
#endif
Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,57 @@
11
#import <XCTest/XCTest.h>
2+
#import <filesystem>
23
#import "ParquetLogger.h"
34

45
@interface ParquetLoggerTest : XCTestCase
56
@end
67

78
@implementation ParquetLoggerTest
89

9-
// Currently, this just demonstrates that Rust code can be called into.
10-
- (void)testBasic {
11-
XCTAssertFalse(FilterContains(1338));
12-
XCTAssertTrue(FilterContains(1337));
10+
- (void)testWriteTable {
11+
auto tmp_path = std::filesystem::temp_directory_path();
12+
try {
13+
auto args =
14+
pedro::wire::table_args_new("test_table", (tmp_path / "test_table.parquet").string());
15+
16+
pedro::wire::table_args_add_column(*args, "number", pedro::wire::CxxColumnType::Int32);
17+
pedro::wire::table_args_add_column(*args, "text", pedro::wire::CxxColumnType::ByteArray);
18+
auto table = pedro::wire::table_new(std::move(args));
19+
20+
pedro::wire::table_push_i32(*table, 0, 1337);
21+
pedro::wire::table_push_string(*table, 1, "foo");
22+
23+
pedro::wire::table_push_i32(*table, 0, 1);
24+
pedro::wire::table_push_i32(*table, 0, 2);
25+
pedro::wire::table_push_i32(*table, 0, 3);
26+
27+
pedro::wire::table_push_string(*table, 1, "bar");
28+
pedro::wire::table_push_string(*table, 1, "baz");
29+
pedro::wire::table_push_string(*table, 1, "qux");
30+
31+
pedro::wire::table_flush(*table);
32+
pedro::wire::table_end(std::move(table));
33+
} catch (const std::exception &e) {
34+
// None of this should throw.
35+
XCTAssertFalse(true, "Exception: %s", e.what());
36+
}
37+
38+
// The file should exist as expected.
39+
std::filesystem::path testFilePath = tmp_path / "test_table.parquet";
40+
XCTAssertTrue(std::filesystem::exists(testFilePath));
41+
}
42+
43+
- (void)testInvalidFlushThrows {
44+
auto tmp_path = std::filesystem::temp_directory_path();
45+
auto args = pedro::wire::table_args_new("test_table", (tmp_path / "test_table.parquet").string());
46+
pedro::wire::table_args_add_column(*args, "number", pedro::wire::CxxColumnType::Int32);
47+
pedro::wire::table_args_add_column(*args, "text", pedro::wire::CxxColumnType::ByteArray);
48+
49+
auto table = pedro::wire::table_new(std::move(args));
50+
pedro::wire::table_push_i32(*table, 0, 1);
51+
pedro::wire::table_push_i32(*table, 0, 2);
52+
53+
// This should throw because we haven't pushed data to all columns.
54+
XCTAssertThrows(pedro::wire::table_flush(*table));
1355
}
1456

1557
@end

Source/santad/Logs/EndpointSecurity/ParquetLogger/parquet_logger.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ mod table;
5656
mod value;
5757
mod writer;
5858

59-
use parquet2::bloom_filter;
60-
61-
// This is just some POC code for CXX that'll be removed later.
62-
// DONOTSUBMIT: Remove this before finishing the PR.
63-
#[no_mangle]
64-
pub extern "C" fn parquet2_1337_bloom_filter_contains(x: i64) -> bool {
65-
let mut bits = vec![0; 32];
66-
bloom_filter::insert(&mut bits, bloom_filter::hash_native::<i64>(1337));
67-
bloom_filter::is_in_set(&bits, bloom_filter::hash_native(x))
68-
}
69-
7059
// This is the main public API.
7160
pub use crate::table::Table;
7261

Source/santad/Logs/EndpointSecurity/ParquetLogger/write_test_file.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
// This demonstrates the use of the C++ API for parquet_logger, which is
66
// implemented in Rust. The C++ API uses an opaque type called Table, which is
77
// returned as a Box (effectively a unique_ptr).
8-
8+
//
9+
// To easily check that the file is valid, load it into Pandas:
10+
//
11+
// import pandas as pd; pd.read_parquet("./test_table.parquet")
912
int main(int argc, char* argv[]) {
1013
try {
1114
if (argc < 2) {

0 commit comments

Comments
 (0)