From 8b458e2c2b9ef352044937945a00e6deb875cb02 Mon Sep 17 00:00:00 2001
From: Edd Robinson <me@edd.io>
Date: Wed, 29 Sep 2021 14:42:42 +0100
Subject: [PATCH] feat: add API for validating a predicate against a chunk:

---
 read_buffer/src/chunk.rs | 7 +++++++
 read_buffer/src/table.rs | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/read_buffer/src/chunk.rs b/read_buffer/src/chunk.rs
index 4b27dc00f9..e0ed0286d4 100644
--- a/read_buffer/src/chunk.rs
+++ b/read_buffer/src/chunk.rs
@@ -210,6 +210,13 @@ impl Chunk {
     // ---- Schema queries
     //
 
+    /// Validates if the predicate can be applied to the table based on the
+    /// schema and the predicate's expressions. Returns an error if the
+    /// predicate cannot be applied.
+    pub fn validate_predicate(&self, predicate: Predicate) -> Result<Predicate, Error> {
+        self.table.validate_predicate(predicate).context(TableError)
+    }
+
     /// Determines if one of more rows in the provided table could possibly
     /// match the provided predicate.
     ///
diff --git a/read_buffer/src/table.rs b/read_buffer/src/table.rs
index d8992c2601..b0d98d8d50 100644
--- a/read_buffer/src/table.rs
+++ b/read_buffer/src/table.rs
@@ -234,6 +234,14 @@ impl Table {
         Arc::clone(&self.table_data.read().meta)
     }
 
+    /// Validates if the predicate can be applied to the table based on the
+    /// schema and the predicate's expressions. Returns an error if the
+    /// predicate cannot be applied.
+    pub fn validate_predicate(&self, predicate: Predicate) -> Result<Predicate, Error> {
+        let table_data = self.table_data.read();
+        Ok(table_data.meta.validate_exprs(predicate)?.into())
+    }
+
     /// Determines if one of more row groups in the `Table` could possibly
     /// contain one or more rows that satisfy the provided predicate.
     pub fn could_pass_predicate(&self, predicate: &Predicate) -> bool {