Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vkorukanti committed Aug 29, 2023
1 parent 83b65e3 commit c9b65ec
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public Predicate getLeft() {
public Predicate getRight() {
return (Predicate) children().get(1);
}

@Override
public String toString() {
return "(" + getLeft() + " AND " + getRight() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public Predicate getLeft() {
public Predicate getRight() {
return (Predicate) children().get(1);
}

@Override
public String toString() {
return "(" + getLeft() + " OR " + getRight() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -69,6 +70,18 @@
* <li>Since version: 3.0.0</li>
* </ul>
* </li>
* <li>Name: <code>ALWAYS_TRUE</code>
* <ul>
* <li>SQL semantic: <code>Constant expression whose value is `true`</code></li>
* <li>Since version: 3.0.0</li>
* </ul>
* </li>
* <li>Name: <code>ALWAYS_FALSE</code>
* <ul>
* <li>SQL semantic: <code>Constant expression whose value is `false`</code></li>
* <li>Since version: 3.0.0</li>
* </ul>
* </li>
* <li>Name: <code>AND</code>
* <ul>
* <li>SQL semantic: <code>expr1 AND expr2</code></li>
Expand Down Expand Up @@ -103,6 +116,18 @@ public List<Expression> children() {
return children;
}

@Override
public String toString() {
if (COMPARATOR_OPERATORS.contains(name)) {
return String.format("(%s %s %s)", children.get(0), name, children.get(1));
}
String args =
children.stream().map(Object::toString).collect(Collectors.joining(","));
return String.format("%s(%s)", name, args);
}

private static final Set<String> COMPARATOR_OPERATORS =
Stream.of("=", ">", ">=", "<", "<=").collect(Collectors.toSet());
/**
* List of supported predicate expressions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static Type findSubFieldType(GroupType groupType, StructField field) {
return null;
}

// TODO: Move these precondition checks into a separate utility class.
/**
* Precondition-style validation that throws {@link IllegalArgumentException}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package io.delta.kernel.defaults.internal.expressions;

import java.util.Collections;
import java.util.List;
import static java.util.Objects.requireNonNull;

import io.delta.kernel.data.ColumnVector;
import io.delta.kernel.expressions.Expression;
import io.delta.kernel.types.DataType;

Expand All @@ -35,7 +37,7 @@
* </ul>
*
* <p>
* The above list of not exhaustive. Based on the need, we can add more casts. We should always
* The above list is not exhaustive. Based on the need, we can add more casts. We should always
* aim the newly added casts to be ANSI SQL compliant. Use the Apache Spark cast function which
* follows ANSI SQL (when enabled) as a reference. @see
*
Expand Down Expand Up @@ -65,6 +67,141 @@ public DataType getOutputType() {

@Override
public List<Expression> children() {
return null;
return Collections.singletonList(input);
}

private abstract static class UpConverter implements ColumnVector {
protected final DataType targetType;
protected final ColumnVector inputVector;

UpConverter(DataType targetType, ColumnVector inputVector) {
this.targetType = targetType;
this.inputVector = inputVector;
}

@Override
public DataType getDataType() {
return targetType;
}

@Override
public boolean isNullAt(int rowId) {
return inputVector.isNullAt(rowId);
}

@Override
public int getSize() {
return inputVector.getSize();
}

@Override
public void close() {
inputVector.close();
}
}

private static class ByteUpConverter extends UpConverter {
ByteUpConverter(DataType targetType, ColumnVector inputVector) {
super(targetType, inputVector);
}

@Override
public short getShort(int rowId) {
return getByte(rowId);
}

@Override
public int getInt(int rowId) {
return getByte(rowId);
}

@Override
public long getLong(int rowId) {
return getByte(rowId);
}

@Override
public float getFloat(int rowId) {
return getByte(rowId);
}

@Override
public double getDouble(int rowId) {
return getByte(rowId);
}
}

private static class ShortUpConverter extends UpConverter {
ShortUpConverter(DataType targetType, ColumnVector inputVector) {
super(targetType, inputVector);
}

@Override
public int getInt(int rowId) {
return getShort(rowId);
}

@Override
public long getLong(int rowId) {
return getShort(rowId);
}

@Override
public float getFloat(int rowId) {
return getShort(rowId);
}

@Override
public double getDouble(int rowId) {
return getShort(rowId);
}
}

private static class IntUpConverter extends UpConverter {
IntUpConverter(DataType targetType, ColumnVector inputVector) {
super(targetType, inputVector);
}

@Override
public long getLong(int rowId) {
return getInt(rowId);
}

@Override
public float getFloat(int rowId) {
return getInt(rowId);
}

@Override
public double getDouble(int rowId) {
return getInt(rowId);
}
}

private static class LongUpConverter extends UpConverter {
LongUpConverter(DataType targetType, ColumnVector inputVector) {
super(targetType, inputVector);
}

@Override
public float getFloat(int rowId) {
return getLong(rowId);
}

@Override
public double getDouble(int rowId) {
return getLong(rowId);
}
}

private static class FloatUpConverter extends UpConverter {
FloatUpConverter(DataType targetType, ColumnVector inputVector) {
super(targetType, inputVector);
}

@Override
public double getDouble(int rowId) {
return getFloat(rowId);
}
}
}
Loading

0 comments on commit c9b65ec

Please sign in to comment.