-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Frame writers: Coerce numeric and array types in certain cases. #16994
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
190f6e2
Frame writers: use getObject when reading string/complex types.
gianm 6638d87
Merge branch 'master' into frame-typecast-selector
gianm d374fe1
Merge branch 'master' into frame-typecast-selector
gianm f3aea17
Use ExprEval.ofType rather than bestEffortOf. Add casting for arrays …
gianm e224671
Coerce in RowBasedColumnSelectorFactory when desired type doesn't match
gianm 5f58b59
Fix error.
gianm f1985d8
Undo RowBasedColumnSelectorFactory change. Account for it in TypeCast…
gianm c0522e5
Use ExprEval#ofType.
gianm 28d36e1
Javadoc.
gianm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| "expectedResults": [ | ||
| { | ||
| "__time": 1672058096000, | ||
| "double_col": 0.0 | ||
| "double_col": null | ||
| } | ||
| ] | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...ing/src/main/java/org/apache/druid/frame/write/cast/ObjectToArrayColumnValueSelector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.frame.write.cast; | ||
|
|
||
| import org.apache.druid.error.DruidException; | ||
| import org.apache.druid.math.expr.ExprEval; | ||
| import org.apache.druid.math.expr.ExpressionType; | ||
| import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector; | ||
| import org.apache.druid.segment.ColumnValueSelector; | ||
| import org.apache.druid.segment.RowIdSupplier; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Wraps a {@link ColumnValueSelector}, calls {@link ColumnValueSelector#getObject()}, interprets that value using | ||
| * {@link ExprEval#ofType}, and casts it using {@link ExprEval#castTo}. | ||
| */ | ||
| public class ObjectToArrayColumnValueSelector implements ColumnValueSelector<Object[]> | ||
| { | ||
| private final ColumnValueSelector<?> selector; | ||
| @Nullable | ||
| private final ExpressionType desiredType; | ||
| @Nullable | ||
| private final RowIdSupplier rowIdSupplier; | ||
|
|
||
| public ObjectToArrayColumnValueSelector( | ||
| final ColumnValueSelector<?> selector, | ||
| final ExpressionType desiredType, | ||
| @Nullable final RowIdSupplier rowIdSupplier | ||
| ) | ||
| { | ||
| this.selector = selector; | ||
| this.desiredType = desiredType; | ||
| this.rowIdSupplier = rowIdSupplier; | ||
|
|
||
| if (!desiredType.isArray() || desiredType.getElementType() == null) { | ||
| throw DruidException.defensive("Expected array with nonnull element type, got[%s]", desiredType); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public double getDouble() | ||
| { | ||
| throw DruidException.defensive("Unexpected call to getDouble on array selector"); | ||
| } | ||
|
|
||
| @Override | ||
| public float getFloat() | ||
| { | ||
| throw DruidException.defensive("Unexpected call to getFloat on array selector"); | ||
| } | ||
|
|
||
| @Override | ||
| public long getLong() | ||
| { | ||
| throw DruidException.defensive("Unexpected call to getLong on array selector"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isNull() | ||
| { | ||
| throw DruidException.defensive("Unexpected call to isNull on array selector"); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Object[] getObject() | ||
| { | ||
| return (Object[]) TypeCastSelectors.bestEffortCoerce(selector.getObject(), desiredType); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<Object[]> classOfObject() | ||
| { | ||
| return Object[].class; | ||
| } | ||
|
|
||
| @Override | ||
| public void inspectRuntimeShape(RuntimeShapeInspector inspector) | ||
| { | ||
| inspector.visit("selector", selector); | ||
| inspector.visit("rowIdSupplier", rowIdSupplier); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.