Skip to content
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

fix: SelectColumn Should Unbox Result Type #6052

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20290,6 +20290,10 @@ public static boolean greaterEquals(float a, BigDecimal b) {
return compareTo(a, b) >= 0;
}

public static BigDecimal negate(BigDecimal a) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should assess if there are further gaps? Maybe the way to get there is by updating the generator and adding it to our process.

return a == null ? null : a.negate();
}

//
// BigInteger ops
//
Expand Down Expand Up @@ -21135,4 +21139,8 @@ public static boolean greaterEquals(BigInteger a, float b) {
public static boolean greaterEquals(float a, BigInteger b) {
return compareTo(a, b) >= 0;
}

public static BigInteger negate(BigInteger a) {
return a == null ? null : a.negate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1717,10 +1717,11 @@ public Class<?> visit(UnaryExpr n, VisitArgs printer) {
// since the original expression was visited by getTypeWithCaching at the beginning of this method.
final Class<?> result = unaryOpOverloadMethod.accept(this, printer);

// Verify that the operator overload method returns the original expected type:
Assert.equals(ret, "ret", result, "result");
// Verify that the operator overload method returns the original expected type (or its unboxed form):
Copy link
Member

Choose a reason for hiding this comment

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

We talked about "smart unboxing" when given a null input that matches a single primitive method. I'm not sure if it makes sense, yet.

Assert.equals(TypeUtils.getUnboxedTypeIfBoxed(ret), "TypeUtils.getUnboxedTypeIfBoxed(ret)",
result, "result");
Comment on lines +1720 to +1722
Copy link
Member

Choose a reason for hiding this comment

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

Should we allow boxed or unboxed?

Assert.equals(TypeUtils.getUnboxedTypeIfBoxed(ret), "TypeUtils.getUnboxedTypeIfBoxed(ret)",
                TypeUtils.getUnboxedTypeIfBoxed(result), "TypeUtils.getUnboxedTypeIfBoxed(result)");


return ret;
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public List<String> initDef(
.endl();

applyUsedVariables(columnDefinitionMap, result.getVariablesUsed(), result.getPossibleParams());
returnedType = result.getType();
returnedType = TypeUtils.getUnboxedTypeIfBoxed(result.getType());
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a healthy change. That said, should we be changing the consumer of returned type to ensure that things are better for all select columns? Or should we check the other implementations of getReturnedType? I'm mainly concerned about the python formula column.

if (returnedType == boolean.class) {
returnedType = Boolean.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ public static AnalyzerContext createContext(

// First pass to initialize all columns and to compile formulas in one batch.
final QueryCompilerRequestProcessor.BatchProcessor compilationProcessor = QueryCompilerRequestProcessor.batch();
for (Map.Entry<String, ColumnSource<?>> entry : columnSources.entrySet()) {
final String name = entry.getKey();
final ColumnSource<?> cs = entry.getValue();
final ColumnDefinition<?> cd = ColumnDefinition.fromGenericType(name, cs.getType(), cs.getComponentType());
columnDefinitions.put(name, cd);
}
parentTable.getDefinition().getColumns().forEach(cd -> columnDefinitions.put(cd.getName(), cd));
Copy link
Member

Choose a reason for hiding this comment

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

I would definitely run nightlies. I would also like you to test out what happens if you run select(), view(), update(), and updateView() preserving a partitioning column: does the output reflect that the column is partitioning, and is that a change?


final Set<String> resultColumnNames = new HashSet<>();
for (final SelectColumn sc : selectColumns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.junit.Rule;
import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
Expand Down Expand Up @@ -1300,4 +1302,28 @@ public void testPropagationOfAttributes() {
Assert.assertTrue(result.isBlink());
}
}

@Test
public void testRegressionGH5998_BigDecimal_negate() {
ExecutionContext.getContext().getQueryScope().putParam("bd_val", BigDecimal.valueOf(123.456));
emptyTable(0).update("A = 0 < -bd_val");
}

@Test
public void testRegressionGH5998_BigInteger_negate() {
ExecutionContext.getContext().getQueryScope().putParam("bi_val", BigInteger.valueOf(123));
emptyTable(0).update("A = 0 < -bi_val");
}

@Test
public void testRegressionGH5998_Double_QSP() {
ExecutionContext.getContext().getQueryScope().putParam("d_val", 123.456);
emptyTable(0).update("A = 0 < -d_val");
}

@Test
public void testRegressionGH5998_Double_NewCol() {
ExecutionContext.getContext().getQueryScope().putParam("d_val", 123.456);
emptyTable(0).update("B = d_val", "A = 0 < -B");
}
}
Loading