Skip to content

Conversation

@haohuaijin
Copy link
Collaborator

@haohuaijin haohuaijin commented Nov 28, 2025

when new a RecordBatch, the schema and column should be match

@github-actions github-actions bot added ☢️ Bug Something isn't working ✏️ Feature labels Nov 28, 2025
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 28, 2025

Greptile Overview

Greptile Summary

Replaced RecordBatch::try_new(schema.clone(), vec![]) with RecordBatch::new_empty(schema.clone()) in the convert_json_to_record_batch function when handling empty data arrays.

  • Uses the more idiomatic new_empty() API for creating empty RecordBatch instances
  • Consistent with existing patterns elsewhere in the codebase (e.g., line 805 in the same file)
  • Eliminates unnecessary Result wrapping since new_empty() doesn't return a Result type

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The change is a simple refactoring that uses a more appropriate API method. RecordBatch::new_empty() is specifically designed for creating empty record batches, whereas RecordBatch::try_new(schema, vec![]) is a workaround. The change is consistent with existing patterns in the same file and improves code clarity without altering behavior.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/config/src/utils/record_batch_ext.rs 5/5 Replaced RecordBatch::try_new(schema.clone(), vec![]) with RecordBatch::new_empty(schema.clone()) for cleaner API usage when handling empty data arrays

Sequence Diagram

sequenceDiagram
    participant Caller
    participant convert_json_to_record_batch
    participant RecordBatch

    Caller->>convert_json_to_record_batch: Call with schema & data[]
    
    alt data.is_empty()
        convert_json_to_record_batch->>RecordBatch: new_empty(schema)
        RecordBatch-->>convert_json_to_record_batch: Empty RecordBatch
        convert_json_to_record_batch-->>Caller: Ok(empty RecordBatch)
    else data has records
        convert_json_to_record_batch->>convert_json_to_record_batch: Pre-allocate builders
        convert_json_to_record_batch->>convert_json_to_record_batch: Create field mappings
        convert_json_to_record_batch->>convert_json_to_record_batch: Process JSON records
        convert_json_to_record_batch->>RecordBatch: try_new(schema, arrays)
        RecordBatch-->>convert_json_to_record_batch: RecordBatch with data
        convert_json_to_record_batch-->>Caller: Ok(RecordBatch)
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@haohuaijin haohuaijin merged commit dd6df54 into main Nov 28, 2025
46 of 53 checks passed
@haohuaijin haohuaijin deleted the fix-record-batch-new branch November 28, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working ✏️ Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants