Skip to content

feat: query parquet files still in staging #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 20, 2025
Merged

Conversation

de-sh
Copy link
Contributor

@de-sh de-sh commented Feb 19, 2025

Fixes #XXXX.

Description

Currently parquet files that are still lying around in staging are not query-able, this PR fixes it.


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

  • New Features

    • Introduced an asynchronous method for creating execution plans based on records from a staging area, improving data query capabilities.
  • Refactor

    • Enhanced modularity and clarity by reorganizing methods related to staging data handling.
    • Improved error handling for better resilience during staging data retrieval.
    • Updated method signatures for improved readability and maintainability.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes enhance staging data processing in the query module by introducing an asynchronous method get_staging_execution_plan in the StandardTableProvider struct. This new method retrieves records from a staging area, applies multiple filters, builds a reversed memory table, and creates a parquet physical plan. Additionally, the scan method has been refactored to make use of this new functionality. Import statements have been reorganized and updated to support these modifications, and error handling has been improved to gracefully manage retrieval failures.

Changes

File(s) Change Summary
src/query/stream_schema_provider.rs Added async method get_staging_execution_plan; refactored scan to use the new method; updated method signatures for collect_from_snapshot, partitioned_files, find_matching_column, and get_hottier_execution_plan; reorganized and updated imports; enhanced error handling.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant STP as StandardTableProvider
    participant SA as StagingArea
    participant M as MemoryTable
    participant PP as ParquetPhysicalPlan

    C->>STP: Call get_staging_execution_plan(filters, projection, etc.)
    STP->>SA: Retrieve staging stream
    SA-->>STP: Return staging records
    STP->>M: Build reversed memory table
    M-->>STP: Reversed memory table
    STP->>PP: Create parquet physical plan
    PP-->>STP: Return execution plan
    STP->>C: Respond with execution plan
Loading

Possibly related PRs

Poem

I'm a rabbit, hopping through code with cheer,
New async paths and refactored flows now appear.
Staging records and plans, all in a line,
Error handling and imports now perfectly align.
With a hop and a skip, my joy is complete—
Carrots and code, together so sweet! 🥕🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 978c24f and 608e717.

📒 Files selected for processing (1)
  • src/query/stream_schema_provider.rs (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: coverage
🔇 Additional comments (4)
src/query/stream_schema_provider.rs (4)

19-67: LGTM! Well-organized imports.

The imports are now logically grouped and follow Rust's standard organization pattern.


221-221: LGTM! Clear and descriptive documentation.

The documentation clearly explains the purpose of the method.


257-259: LGTM! Appropriate handling of race conditions.

The code correctly handles the race condition where files might be deleted after listing but before reading by simply skipping inaccessible files. This is the right approach for staging area operations.


406-412: LGTM! Improved type references.

The method signatures now use direct type references instead of module paths, which improves code readability.

Also applies to: 898-899


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/query/stream_schema_provider.rs (1)

225-267: Well-implemented staging data handling with good error management.

The implementation:

  • Gracefully handles missing streams and file metadata errors
  • Efficiently partitions files across CPU cores
  • Uses reversed memory table for optimized querying

However, consider adding the following improvements:

  1. Add a size limit or cleanup mechanism for the staging area to prevent unbounded memory growth
  2. Consider implementing batch processing for large staging areas
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e02f29 and afa0161.

📒 Files selected for processing (1)
  • src/query/stream_schema_provider.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: coverage
🔇 Additional comments (2)
src/query/stream_schema_provider.rs (2)

19-70: LGTM! Import changes are well-organized.

The new imports are necessary for the added functionality and are properly organized by crate.


488-498: LGTM! Scan method changes properly integrate staging data.

The changes effectively integrate staging data querying while maintaining backward compatibility and following existing error handling patterns.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 19, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/query/stream_schema_provider.rs (1)

256-258: Consider adding retry logic for parquet file access.

There's a potential race condition where parquet files might be moved to object store between listing and access. The comment acknowledges this, but we should consider implementing retry logic.

Consider implementing a retry mechanism with exponential backoff for file access operations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afa0161 and a0d2c8e.

📒 Files selected for processing (1)
  • src/query/stream_schema_provider.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: coverage
🔇 Additional comments (2)
src/query/stream_schema_provider.rs (2)

19-70: LGTM! Well-organized imports.

The imports are logically grouped and include all necessary dependencies for the new staging query functionality.


493-502: LGTM! Clean integration of staging execution plan.

The integration of get_staging_execution_plan into the scan method is well-implemented and maintains consistent error handling.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/query/stream_schema_provider.rs (1)

241-250: Extract partitioning logic into a separate function.

The partitioning logic could be reused elsewhere and would benefit from being a separate function.

Consider extracting the partitioning logic:

+fn partition_files<T>(files: impl Iterator<Item = T>, target_partition: usize) -> Vec<Vec<T>> {
+    let mut partitioned = Vec::from_iter((0..target_partition).map(|_| Vec::new()));
+    for (index, file) in files.enumerate() {
+        partitioned[index % target_partition].push(file);
+    }
+    partitioned
+}

 // In get_staging_execution_plan:
-let target_partition = num_cpus::get();
-let mut partitioned_files = Vec::from_iter((0..target_partition).map(|_| Vec::new()));
-for (index, file_path) in staging.parquet_files().into_iter().enumerate() {
-    let Ok(file_meta) = file_path.metadata() else {
-        continue;
-    };
-    let file = PartitionedFile::new(file_path.display().to_string(), file_meta.len());
-    partitioned_files[index % target_partition].push(file)
-}
+let partitioned_files = partition_files(
+    staging.parquet_files().into_iter().filter_map(|file_path| {
+        file_path.metadata().ok().map(|meta| 
+            PartitionedFile::new(file_path.display().to_string(), meta.len())
+        )
+    }),
+    num_cpus::get()
+);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0d2c8e and 5e1cef9.

📒 Files selected for processing (1)
  • src/query/stream_schema_provider.rs (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
🔇 Additional comments (2)
src/query/stream_schema_provider.rs (2)

235-235: Add error handling for recordbatches_cloned.

The recordbatches_cloned call could potentially fail, but the error is not being handled.


230-232: LGTM! Graceful error handling.

The early return with Ok(()) when the stream is not found is a clean approach that prevents unnecessary processing.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 19, 2025
@nikhilsinhaparseable
Copy link
Contributor

@de-sh in case of multiple parquet files present in staging,
if i send a query - select * from stream-name limit 10
my expectation is to see the latest 10 records out of all the parquets in the staging, which is not the case, i dont see records from the last created parquet but from a different one.
Please verify this once.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/query/stream_schema_provider.rs (1)

236-236: ⚠️ Potential issue

Add error handling for recordbatches_cloned.

The recordbatches_cloned call could potentially fail, but the error is not being handled.

Apply this diff:

-let records = staging.recordbatches_cloned(&self.schema);
+let records = staging.recordbatches_cloned(&self.schema)
+    .map_err(|e| DataFusionError::External(Box::new(e)))?;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e1cef9 and 1b066f0.

📒 Files selected for processing (1)
  • src/query/stream_schema_provider.rs (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: coverage

Comment on lines 245 to 251
for (index, file_path) in staging.parquet_files().into_iter().enumerate() {
let Ok(file_meta) = file_path.metadata() else {
continue;
};
let file = PartitionedFile::new(file_path.display().to_string(), file_meta.len());
partitioned_files[index % target_partition].push(file)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

Consider sorting parquet files by timestamp.

Based on the user feedback about query results not including records from the most recently created parquet file, the files should be sorted by timestamp before partitioning to ensure consistent query results.

Let's verify if there's a timestamp field in the parquet files that we can use for sorting:


🏁 Script executed:

#!/bin/bash
# Description: Check for timestamp fields in parquet files
# Look for timestamp-related field definitions in the code
rg -A 5 'timestamp|time|_at' --type rust

Length of output: 71541


Action: Sort Parquet Files by Timestamp

It appears that the current loop in src/query/stream_schema_provider.rs (lines 245–251) enumerates the parquet files without any ordering. Given the user feedback about recent records being missed, we recommend sorting these files by their creation or modification timestamp before partitioning. Note that elsewhere in the repository (e.g., through usage of DEFAULT_TIMESTAMP_KEY and timestamp fields in the schema), there is clear support for time-based ordering.

  • Location: src/query/stream_schema_provider.rs, lines 245–251.
  • Issue: The parquet files are partitioned using their original order (via enumerate() and modulo assignment), which may inadvertently skip the most recently created file.
  • Recommendation: Sort the parquet files—using a timestamp extracted from file metadata (e.g., by calling file_path.metadata()?.modified()) or an equivalent field—prior to applying the partitioning logic. Make sure to handle potential errors when retrieving the timestamp.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
src/query/stream_schema_provider.rs (2)

236-236: 🛠️ Refactor suggestion

Add error handling for recordbatches_cloned.
This call may fail, and the code currently ignores that possibility.

-let records = staging.recordbatches_cloned(&self.schema);
+let records = staging.recordbatches_cloned(&self.schema)
+    .map_err(|e| DataFusionError::External(Box::new(e)))?;

242-245: 🛠️ Refactor suggestion

Sort by modification time rather than filename, if possible.
Relying on reversed filename order might skip the newest file, per user feedback.

- parquet_files.sort_by(|a, b| a.cmp(b).reverse());
+ // Example approach using modification times:
+ parquet_files.sort_by_key(|f| f.metadata().and_then(|m| m.modified()).ok());
+ parquet_files.reverse();
🧹 Nitpick comments (1)
src/query/stream_schema_provider.rs (1)

221-230: Fix minor spelling in documentation.
“exection” should be spelled “execution.”

-    /// Create an exection plan over the records in arrows...
+    /// Create an execution plan over the records in arrows...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b066f0 and 978c24f.

📒 Files selected for processing (1)
  • src/query/stream_schema_provider.rs (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: coverage
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
🔇 Additional comments (13)
src/query/stream_schema_provider.rs (13)

19-20: No issues found.
Imports look consistent with the rest of the file.


26-26: No issues found.
The addition of Session appears appropriate for upcoming usage.


28-28: No issues found.
The Precision import is relevant for column statistics usage.


40-43: No issues found.
These new imports (BinaryExpr, Operator, etc.) match the DataFusion expressions used below.


64-65: No issues found.
Inclusion of Mode and STREAM_EXISTS aligns with the code’s logic.


231-233: Consider returning an error or logging a warning when the stream doesn't exist.
Currently, this block silently returns Ok(()). Confirm whether ignoring a missing staging stream is intended.


246-255: No issues found.
Skipping inaccessible files aligns with the ephemeral nature of staging.


257-272: No issues found.
This logic correctly calls create_parquet_physical_plan to handle any staged parquet files.


328-328: No issues found.
Changing the parameter type to Vec<File> is consistent with the updated references.


332-332: No issues found.
Storing column statistics in a HashMap remains a clear approach.


340-340: No issues found.
Deconstructing File matches the rest of the changes in this refactor.


407-412: No issues found.
Adjusting the signature to return Vec<File> aligns with the type refactor.


898-898: No issues found.
The reference to Column is consistent with the updated imports.

Signed-off-by: Devdutt Shenoi <[email protected]>
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable left a comment

Choose a reason for hiding this comment

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

LGTM

@nitisht nitisht merged commit 5e3577f into parseablehq:main Feb 20, 2025
14 checks passed
@de-sh de-sh deleted the parquet branch February 20, 2025 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants