Skip to content

Commit

Permalink
cleaned up warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyshazam committed Feb 6, 2024
1 parent 4989bf6 commit becb3f2
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 330 deletions.
84 changes: 0 additions & 84 deletions src/DeltaLake/Bridge/ForwardedLog.cs

This file was deleted.

11 changes: 5 additions & 6 deletions src/DeltaLake/Bridge/RecordBatchReader.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Apache.Arrow;
using Apache.Arrow.Ipc;

namespace DeltaLake.Bridge
{
internal class RecordBatchReader : IArrowArrayStream
internal sealed class RecordBatchReader : IArrowArrayStream
{
private readonly IEnumerable<RecordBatch> _recordBatches;
private readonly IEnumerator<RecordBatch> _enumerator;

public RecordBatchReader(IEnumerable<RecordBatch> recordBatches, Schema schema)
{
_recordBatches = recordBatches;
_enumerator = _recordBatches.GetEnumerator();
_enumerator = recordBatches.GetEnumerator();
Schema = schema;
}

Expand All @@ -32,7 +29,9 @@ public ValueTask<RecordBatch> ReadNextRecordBatchAsync(System.Threading.Cancella
return ValueTask.FromResult(_enumerator.Current);
}

return ValueTask.FromResult<RecordBatch>(default(RecordBatch));
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
return ValueTask.FromResult<RecordBatch>(default);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}
}
15 changes: 0 additions & 15 deletions src/DeltaLake/Bridge/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Text.Json;
using System.Threading.Tasks;
using Apache.Arrow.C;
using Microsoft.Extensions.Logging;

namespace DeltaLake.Bridge
{
Expand All @@ -15,15 +14,6 @@ namespace DeltaLake.Bridge
/// </summary>
internal sealed class Runtime : SafeHandle
{
/*
private static readonly Func<ForwardedLog, Exception?, string> ForwardLogMessageFormatter =
LogMessageFormatter;
private readonly bool forwardLoggerIncludeFields;*/
private readonly GCHandle? forwardLoggerCallback;

private ILogger? forwardLogger;

/// <summary>
/// Initializes a new instance of the <see cref="Runtime"/> class.
/// </summary>
Expand Down Expand Up @@ -234,13 +224,8 @@ internal unsafe void FreeByteArray(Interop.ByteArray* byteArray)
/// <inheritdoc />
protected override unsafe bool ReleaseHandle()
{
forwardLogger = null;
forwardLoggerCallback?.Free();
Interop.Methods.runtime_free(Ptr);
return true;
}

private static string LogMessageFormatter(ForwardedLog state, Exception? error) =>
state.ToString();
}
}
8 changes: 4 additions & 4 deletions src/DeltaLake/Bridge/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public async Task<string> HistoryAsync(ulong limit, ICancellationToken cancellat
Methods.history(
_runtime.Ptr,
_ptr,
(UIntPtr)limit,
new UIntPtr(limit),
scope.CancellationToken(cancellationToken),
scope.FunctionPointer<Interop.GenericErrorCallback>((success, fail) =>
{
Expand Down Expand Up @@ -506,7 +506,7 @@ public async Task UpdateIncrementalAsync(ICancellationToken cancellationToken)
await tsc.Task.ConfigureAwait(false);
}

public Metadata Metadata()
public DeltaLake.Table.TableMetadata Metadata()
{
unsafe
{
Expand All @@ -518,11 +518,11 @@ public Metadata Metadata()

try
{
return DeltaLake.Table.Metadata.FromUnmanaged(result.metadata);
return DeltaLake.Table.TableMetadata.FromUnmanaged(result.metadata);
}
finally
{
var release = (delegate* unmanaged<TableMetadata*, void>)result.metadata->release;
var release = (delegate* unmanaged<Interop.TableMetadata*, void>)result.metadata->release;
release(result.metadata);
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/DeltaLake/Bridge/include/delta-lake-bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,16 @@ void dynamic_array_free(struct Runtime *runtime, const struct DynamicArray *arra

struct PartitionFilterList *partition_filter_list_new(uintptr_t capacity);

bool partition_filter_list_add_binary(struct PartitionFilterList *list,
const struct ByteArrayRef *key,
enum PartitionFilterBinaryOp op,
const struct ByteArrayRef *value);

bool partition_filter_list_add_set(struct PartitionFilterList *list,
const struct ByteArrayRef *key,
enum PartitionFilterBinaryOp op,
const struct ByteArrayRef *value,
uintptr_t value_count);
bool partition_filter_list_add_binary(struct PartitionFilterList *_list,
const struct ByteArrayRef *_key,
enum PartitionFilterBinaryOp _op,
const struct ByteArrayRef *_value);

bool partition_filter_list_add_set(struct PartitionFilterList *_list,
const struct ByteArrayRef *_key,
enum PartitionFilterBinaryOp _op,
const struct ByteArrayRef *_value,
uintptr_t _value_count);

void partition_filter_list_free(struct PartitionFilterList *list);

Expand Down
29 changes: 1 addition & 28 deletions src/DeltaLake/Bridge/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
use deltalake::datafusion::sql::sqlparser::parser::ParserError;

use crate::{runtime::Runtime, ByteArray, ByteArrayRef};
use crate::{runtime::Runtime, ByteArray};

#[repr(C)]
pub struct DeltaTableError {
code: DeltaTableErrorCode,
error: ByteArray,
}

#[repr(C)]
pub struct DeltaTableErrorRef {
code: DeltaTableErrorCode,
error: ByteArrayRef,
}

impl DeltaTableErrorRef {
pub(crate) fn new(code: DeltaTableErrorCode, error: &str) -> Self {
Self {
code,
error: ByteArrayRef::from_str(error),
}
}
}

#[repr(C)]
pub enum DeltaTableErrorCode {
Utf8 = 0,
Expand Down Expand Up @@ -145,18 +130,6 @@ impl DeltaTableError {
Self::new(_runtime, code, &error_string)
}

pub(crate) fn from_cancellation() -> Self {
DeltaTableError {
code: DeltaTableErrorCode::OperationCanceled,
error: ByteArray {
data: std::ptr::null(),
size: 0,
cap: 0,
disable_free: true,
},
}
}

pub(crate) fn into_raw(self) -> *mut DeltaTableError {
Box::into_raw(Box::new(self))
}
Expand Down
54 changes: 3 additions & 51 deletions src/DeltaLake/Bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl KeyValuePair {
ManuallyDrop::new(mapped).as_mut_ptr()
}

#[allow(dead_code)]
pub(crate) fn from_hash_map(input: HashMap<String, String>) -> *mut *mut Self {
ManuallyDrop::new(
input
Expand All @@ -90,13 +91,9 @@ impl KeyValuePair {
impl Drop for KeyValuePair {
fn drop(&mut self) {
unsafe {
let _ = String::from_raw_parts(self.key as *mut u8, self.key_length, self.key_length);
let _ = String::from_raw_parts(self.key, self.key_length, self.key_length);
if !self.value.is_null() {
let _ = String::from_raw_parts(
self.value as *mut u8,
self.value_length,
self.value_length,
);
let _ = String::from_raw_parts(self.value, self.value_length, self.value_length);
}
}
}
Expand Down Expand Up @@ -168,33 +165,10 @@ pub struct ByteArrayRef {
}

impl ByteArrayRef {
fn from_str(s: &str) -> ByteArrayRef {
ByteArrayRef {
data: s.as_ptr(),
size: s.len(),
}
}

fn from_string(s: &String) -> ByteArrayRef {
ByteArrayRef {
data: s.as_ptr(),
size: s.len(),
}
}

fn to_slice(&self) -> &[u8] {
unsafe { std::slice::from_raw_parts(self.data, self.size) }
}

#[allow(clippy::mut_from_ref)]
fn to_slice_mut(&self) -> &mut [u8] {
unsafe { std::slice::from_raw_parts_mut(self.data as *mut u8, self.size) }
}

fn to_vec(&self) -> Vec<u8> {
self.to_slice().to_vec()
}

fn to_str(&self) -> &str {
// Trust caller to send UTF8. Even if we did do a checked call here with
// error, the caller can still have a bad pointer or something else
Expand All @@ -215,14 +189,6 @@ impl ByteArrayRef {
}
}

fn to_option_vec(&self) -> Option<Vec<u8>> {
if self.size == 0 {
None
} else {
Some(self.to_vec())
}
}

fn to_option_str(&self) -> Option<&str> {
if self.size == 0 {
None
Expand All @@ -234,20 +200,6 @@ impl ByteArrayRef {
fn to_option_string(&self) -> Option<String> {
self.to_option_str().map(str::to_string)
}

fn to_str_map_on_newlines(&self) -> HashMap<&str, &str> {
let strs: Vec<&str> = self.to_str().split('\n').collect();
strs.chunks_exact(2)
.map(|pair| (pair[0], pair[1]))
.collect()
}

fn to_string_map_on_newlines(&self) -> HashMap<String, String> {
self.to_str_map_on_newlines()
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect()
}
}

#[repr(C)]
Expand Down
Loading

0 comments on commit becb3f2

Please sign in to comment.