Skip to content

Commit 4d9b080

Browse files
committed
format
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 6063e06 commit 4d9b080

6 files changed

Lines changed: 38 additions & 38 deletions

File tree

java/vortex-spark/src/main/java/dev/vortex/spark/read/SparkPredicateToVortexExpression.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import dev.vortex.api.Expression;
77
import dev.vortex.api.Expression.BinaryOp;
88
import dev.vortex.api.Expression.TimeUnit;
9+
import java.math.BigDecimal;
10+
import java.math.BigInteger;
11+
import java.util.ArrayList;
12+
import java.util.Arrays;
13+
import java.util.List;
14+
import java.util.Map;
15+
import java.util.Optional;
916
import org.apache.spark.sql.connector.expressions.Literal;
1017
import org.apache.spark.sql.connector.expressions.NamedReference;
1118
import org.apache.spark.sql.connector.expressions.filter.AlwaysFalse;
@@ -33,14 +40,6 @@
3340
import org.apache.spark.sql.types.TimestampType;
3441
import org.apache.spark.unsafe.types.UTF8String;
3542

36-
import java.math.BigDecimal;
37-
import java.math.BigInteger;
38-
import java.util.ArrayList;
39-
import java.util.Arrays;
40-
import java.util.List;
41-
import java.util.Map;
42-
import java.util.Optional;
43-
4443
/**
4544
* Translates {@link Predicate Spark V2 predicates} into Vortex {@link Expression}s for predicate pushdown.
4645
*
@@ -50,16 +49,15 @@
5049
*/
5150
final class SparkPredicateToVortexExpression {
5251

53-
private SparkPredicateToVortexExpression() {
54-
}
52+
private SparkPredicateToVortexExpression() {}
5553

5654
/**
5755
* Returns true if the given Spark predicate can be translated to a Vortex expression and every named reference
5856
* resolves to a real field path under {@code dataColumnTypes}.
5957
*
6058
* <p>{@code dataColumnTypes} maps each pushable top-level column name to its top-level Spark {@link DataType};
61-
* partition columns and columns the scan does not project should not appear in the map. For nested references
62-
* (for example {@code info.email}) the validator walks the named reference part by part, descending into
59+
* partition columns and columns the scan does not project should not appear in the map. For nested references (for
60+
* example {@code info.email}) the validator walks the named reference part by part, descending into
6361
* {@link StructType} fields so that {@code info} must be a struct that contains an {@code email} field.
6462
*
6563
* <p>This is the cheap check used in {@code SupportsPushDownV2Filters.pushPredicates} to decide which predicates
@@ -77,8 +75,7 @@ static boolean isPushable(Predicate predicate, Map<String, DataType> dataColumnT
7775

7876
/**
7977
* Walks {@code parts} against {@code dataColumnTypes}, descending through {@link StructType} fields for
80-
* dot-separated nested references. Returns true only when every part resolves to an actual field in the
81-
* schema.
78+
* dot-separated nested references. Returns true only when every part resolves to an actual field in the schema.
8279
*/
8380
private static boolean resolveFieldPath(String[] parts, Map<String, DataType> dataColumnTypes) {
8481
if (parts.length == 0) {
@@ -102,7 +99,9 @@ private static boolean resolveFieldPath(String[] parts, Map<String, DataType> da
10299
}
103100

104101
private static Optional<StructField> findField(StructType struct, String name) {
105-
return Arrays.stream(struct.fields()).filter(structField -> structField.name().equals(name)).findFirst();
102+
return Arrays.stream(struct.fields())
103+
.filter(structField -> structField.name().equals(name))
104+
.findFirst();
106105
}
107106

108107
private static boolean isStructurallyPushable(Predicate predicate) {
@@ -135,7 +134,7 @@ private static boolean isStructurallyPushable(Predicate predicate) {
135134
yield true;
136135
}
137136
case "STARTS_WITH", "ENDS_WITH", "CONTAINS" ->
138-
children.length == 2 && isPushableFieldRef(children[0]) && isPushableStringLiteral(children[1]);
137+
children.length == 2 && isPushableFieldRef(children[0]) && isPushableStringLiteral(children[1]);
139138
// `BOOLEAN_EXPRESSION` wraps a bare boolean-valued child. We only handle the case
140139
// where the child itself is a field reference (e.g. `WHERE bool_col`).
141140
case "BOOLEAN_EXPRESSION" -> children.length == 1 && isPushableFieldRef(children[0]);
@@ -178,12 +177,12 @@ static Optional<Expression> convert(Predicate predicate) {
178177
case "=", "<>", "!=", ">", ">=", "<", "<=" -> convertComparison(predicate.name(), children);
179178
case "IS_NULL" -> children.length == 1 ? columnOf(children[0]).map(Expression::isNull) : Optional.empty();
180179
case "IS_NOT_NULL" ->
181-
children.length == 1 ? columnOf(children[0]).map(Expression::isNotNull) : Optional.empty();
180+
children.length == 1 ? columnOf(children[0]).map(Expression::isNotNull) : Optional.empty();
182181
case "IN" -> convertIn(children);
183182
case "STARTS_WITH" ->
184-
convertStringMatch(children, /* leadingWildcard= */ false, /* trailingWildcard= */ true);
183+
convertStringMatch(children, /* leadingWildcard= */ false, /* trailingWildcard= */ true);
185184
case "ENDS_WITH" ->
186-
convertStringMatch(children, /* leadingWildcard= */ true, /* trailingWildcard= */ false);
185+
convertStringMatch(children, /* leadingWildcard= */ true, /* trailingWildcard= */ false);
187186
case "CONTAINS" -> convertStringMatch(children, /* leadingWildcard= */ true, /* trailingWildcard= */ true);
188187
case "BOOLEAN_EXPRESSION" -> children.length == 1 ? columnOf(children[0]) : Optional.empty();
189188
default -> Optional.empty();
@@ -327,9 +326,7 @@ private static boolean isFieldRefExpr(org.apache.spark.sql.connector.expressions
327326
return expr instanceof NamedReference;
328327
}
329328

330-
/**
331-
* Returns the Vortex column expression for a Spark named reference, walking nested struct fields.
332-
*/
329+
/** Returns the Vortex column expression for a Spark named reference, walking nested struct fields. */
333330
private static Optional<Expression> columnOf(org.apache.spark.sql.connector.expressions.Expression expr) {
334331
if (!(expr instanceof NamedReference)) {
335332
return Optional.empty();
@@ -501,9 +498,7 @@ private static Optional<Expression> convertLiteral(Object value, DataType dataTy
501498
return Optional.empty();
502499
}
503500

504-
/**
505-
* Extract the unscaled integer value of a Spark decimal literal at the supplied {@code scale}.
506-
*/
501+
/** Extract the unscaled integer value of a Spark decimal literal at the supplied {@code scale}. */
507502
private static BigInteger unscaledValueOf(Object value, int scale) {
508503
BigDecimal decimal;
509504
if (value instanceof Decimal) {

java/vortex-spark/src/main/java/dev/vortex/spark/read/VortexScan.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
package dev.vortex.spark.read;
55

6-
import java.util.Arrays;
76
import dev.vortex.api.DataSource;
87
import dev.vortex.api.Session;
98
import dev.vortex.jni.NativeFiles;
109
import dev.vortex.spark.VortexSparkSession;
10+
import java.util.Arrays;
1111
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
@@ -16,8 +16,8 @@
1616
import java.util.stream.Stream;
1717
import org.apache.spark.sql.connector.catalog.CatalogV2Util;
1818
import org.apache.spark.sql.connector.catalog.Column;
19-
import org.apache.spark.sql.connector.expressions.filter.Predicate;
2019
import org.apache.spark.sql.connector.expressions.NamedReference;
20+
import org.apache.spark.sql.connector.expressions.filter.Predicate;
2121
import org.apache.spark.sql.connector.read.Batch;
2222
import org.apache.spark.sql.connector.read.Scan;
2323
import org.apache.spark.sql.connector.read.Statistics;
@@ -59,7 +59,7 @@ public VortexScan(
5959
List<String> paths,
6060
List<Column> tableColumns,
6161
List<Column> readColumns,
62-
Predicate[] pushedPredicates,
62+
Predicate[] pushedPredicates,
6363
Map<String, String> formatOptions) {
6464
this.paths = paths;
6565
this.tableColumns = tableColumns;

java/vortex-spark/src/main/java/dev/vortex/spark/read/VortexScanBuilder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ public Scan build() {
119119
// Allow empty columns for operations like count() that don't need actual column data
120120
// If no columns are specified, we'll read the minimal schema needed
121121

122-
return new VortexScan(paths, List.copyOf(this.tableColumns), List.copyOf(this.readColumns), pushedPredicates, this.formatOptions);
122+
return new VortexScan(
123+
paths,
124+
List.copyOf(this.tableColumns),
125+
List.copyOf(this.readColumns),
126+
pushedPredicates,
127+
this.formatOptions);
123128
}
124129

125130
/**

vortex-duckdb/src/table_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub fn statistics(bind_data: &TableFunctionBind, column_index: usize) -> Option<
439439
if children.len() != 1 {
440440
return None;
441441
}
442-
let MultiLayoutChild::Opened(reader) = &children[0] else {
442+
let MultiLayoutChild::Opened { reader, .. } = &children[0] else {
443443
return None;
444444
};
445445
let stats_sets = match reader.as_any().downcast_ref::<FileStatsLayoutReader>() {

vortex-jni/src/data_source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ pub extern "system" fn Java_dev_vortex_jni_NativeDataSource_byteSize(
265265
try_or_throw(&mut env, |env| {
266266
let ds = unsafe { NativeDataSource::from_ptr(pointer) };
267267
let (bytes, precision) = match ds.inner.byte_size() {
268-
Some(Precision::Exact(b)) => (b as jlong, 2),
269-
Some(Precision::Inexact(b)) => (b as jlong, 1),
270-
None => (0, 0),
268+
Precision::Exact(b) => (b as jlong, 2),
269+
Precision::Inexact(b) => (b as jlong, 1),
270+
Precision::Absent => (0, 0),
271271
};
272272
out.set_region(env, 0, &[bytes, precision])?;
273273
Ok(())

vortex-layout/src/scan/multi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ impl DataSource for MultiLayoutDataSource {
249249
}
250250
}
251251

252-
fn byte_size(&self) -> Option<Precision<u64>> {
252+
fn byte_size(&self) -> Precision<u64> {
253253
let total_count = self.children.len() as u64;
254254
if total_count == 0 {
255-
return Some(Precision::exact(0u64));
255+
return Precision::exact(0u64);
256256
}
257257

258258
let mut sum: u64 = 0;
@@ -265,15 +265,15 @@ impl DataSource for MultiLayoutDataSource {
265265
}
266266

267267
if known_count == 0 {
268-
return None;
268+
return Precision::Absent;
269269
}
270270

271271
if known_count == total_count {
272-
Some(Precision::exact(sum))
272+
Precision::exact(sum)
273273
} else {
274274
let avg = sum / known_count;
275275
let extrapolated = avg.saturating_mul(total_count);
276-
Some(Precision::inexact(extrapolated))
276+
Precision::inexact(extrapolated)
277277
}
278278
}
279279

0 commit comments

Comments
 (0)