-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Numeric array support for columnar frames (#15917)
Columnar frames used in subquery materialization and window functions now support numeric arrays.
- Loading branch information
1 parent
2c0d112
commit a1b2c73
Showing
15 changed files
with
1,120 additions
and
62 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...sing/src/main/java/org/apache/druid/frame/read/columnar/DoubleArrayFrameColumnReader.java
This file contains 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,64 @@ | ||
/* | ||
* 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.read.columnar; | ||
|
||
import com.google.common.math.LongMath; | ||
import org.apache.datasketches.memory.Memory; | ||
import org.apache.druid.frame.Frame; | ||
import org.apache.druid.frame.write.columnar.FrameColumnWriters; | ||
import org.apache.druid.segment.column.ColumnType; | ||
|
||
/** | ||
* Reader for columns written by {@link org.apache.druid.frame.write.columnar.DoubleArrayFrameColumnWriter} | ||
* | ||
* @see NumericArrayFrameColumnReader | ||
* @see org.apache.druid.frame.write.columnar.NumericArrayFrameColumnWriter for column's layout in memory | ||
*/ | ||
public class DoubleArrayFrameColumnReader extends NumericArrayFrameColumnReader | ||
{ | ||
public DoubleArrayFrameColumnReader(int columnNumber) | ||
{ | ||
super(FrameColumnWriters.TYPE_DOUBLE_ARRAY, ColumnType.DOUBLE_ARRAY, columnNumber); | ||
} | ||
|
||
@Override | ||
NumericArrayFrameColumn column(Frame frame, Memory memory, ColumnType columnType) | ||
{ | ||
return new DoubleArrayFrameColumn(frame, memory, columnType); | ||
} | ||
|
||
private static class DoubleArrayFrameColumn extends NumericArrayFrameColumn | ||
{ | ||
public DoubleArrayFrameColumn( | ||
Frame frame, | ||
Memory memory, | ||
ColumnType columnType | ||
) | ||
{ | ||
super(frame, memory, columnType); | ||
} | ||
|
||
@Override | ||
Number getElement(Memory memory, long rowDataOffset, int cumulativeIndex) | ||
{ | ||
return memory.getDouble(LongMath.checkedAdd(rowDataOffset, (long) cumulativeIndex * Double.BYTES)); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ssing/src/main/java/org/apache/druid/frame/read/columnar/FloatArrayFrameColumnReader.java
This file contains 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,64 @@ | ||
/* | ||
* 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.read.columnar; | ||
|
||
import com.google.common.math.LongMath; | ||
import org.apache.datasketches.memory.Memory; | ||
import org.apache.druid.frame.Frame; | ||
import org.apache.druid.frame.write.columnar.FrameColumnWriters; | ||
import org.apache.druid.segment.column.ColumnType; | ||
|
||
/** | ||
* Reader for columns written by {@link org.apache.druid.frame.write.columnar.FloatArrayFrameColumnWriter} | ||
* | ||
* @see NumericArrayFrameColumnReader | ||
* @see org.apache.druid.frame.write.columnar.NumericArrayFrameColumnWriter for column's layout in memory | ||
*/ | ||
public class FloatArrayFrameColumnReader extends NumericArrayFrameColumnReader | ||
{ | ||
public FloatArrayFrameColumnReader(int columnNumber) | ||
{ | ||
super(FrameColumnWriters.TYPE_FLOAT_ARRAY, ColumnType.FLOAT_ARRAY, columnNumber); | ||
} | ||
|
||
@Override | ||
NumericArrayFrameColumn column(Frame frame, Memory memory, ColumnType columnType) | ||
{ | ||
return new FloatArrayFrameColumn(frame, memory, columnType); | ||
} | ||
|
||
private static class FloatArrayFrameColumn extends NumericArrayFrameColumn | ||
{ | ||
public FloatArrayFrameColumn( | ||
Frame frame, | ||
Memory memory, | ||
ColumnType columnType | ||
) | ||
{ | ||
super(frame, memory, columnType); | ||
} | ||
|
||
@Override | ||
Number getElement(Memory memory, long rowDataOffset, int cumulativeIndex) | ||
{ | ||
return memory.getFloat(LongMath.checkedAdd(rowDataOffset, (long) cumulativeIndex * Float.BYTES)); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
processing/src/main/java/org/apache/druid/frame/read/columnar/FrameColumnReaderUtils.java
This file contains 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,66 @@ | ||
/* | ||
* 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.read.columnar; | ||
|
||
import org.apache.datasketches.memory.Memory; | ||
|
||
public class FrameColumnReaderUtils | ||
{ | ||
/** | ||
* Adjusts a negative cumulative row length from {@link #getCumulativeRowLength(Memory, long, int)} to be the actual | ||
* positive length. | ||
*/ | ||
public static int adjustCumulativeRowLength(final int cumulativeRowLength) | ||
{ | ||
if (cumulativeRowLength < 0) { | ||
return -(cumulativeRowLength + 1); | ||
} else { | ||
return cumulativeRowLength; | ||
} | ||
} | ||
|
||
/** | ||
* Returns cumulative row length, if the row is not null itself, or -(cumulative row length) - 1 if the row is | ||
* null itself. | ||
* | ||
* To check if the return value from this function indicate a null row, use {@link #isNullRow(int)} | ||
* | ||
* To get the actual cumulative row length, use {@link FrameColumnReaderUtils#adjustCumulativeRowLength(int)}. | ||
*/ | ||
public static int getCumulativeRowLength(final Memory memory, final long offset, final int physicalRow) | ||
{ | ||
// Note: only valid to call this if multiValue = true. | ||
return memory.getInt(offset + (long) Integer.BYTES * physicalRow); | ||
} | ||
|
||
public static int getAdjustedCumulativeRowLength(final Memory memory, final long offset, final int physicalRow) | ||
{ | ||
return adjustCumulativeRowLength(getCumulativeRowLength(memory, offset, physicalRow)); | ||
} | ||
|
||
/** | ||
* When given a return value from {@link FrameColumnReaderUtils#getCumulativeRowLength(Memory, long, int)}, returns whether the row is | ||
* null itself (i.e. a null array). | ||
*/ | ||
public static boolean isNullRow(final int cumulativeRowLength) | ||
{ | ||
return cumulativeRowLength < 0; | ||
} | ||
} |
This file contains 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
64 changes: 64 additions & 0 deletions
64
...essing/src/main/java/org/apache/druid/frame/read/columnar/LongArrayFrameColumnReader.java
This file contains 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,64 @@ | ||
/* | ||
* 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.read.columnar; | ||
|
||
import com.google.common.math.LongMath; | ||
import org.apache.datasketches.memory.Memory; | ||
import org.apache.druid.frame.Frame; | ||
import org.apache.druid.frame.write.columnar.FrameColumnWriters; | ||
import org.apache.druid.segment.column.ColumnType; | ||
|
||
/** | ||
* Reader for columns written by {@link org.apache.druid.frame.write.columnar.LongArrayFrameColumnWriter} | ||
* | ||
* @see NumericArrayFrameColumnReader | ||
* @see org.apache.druid.frame.write.columnar.NumericArrayFrameColumnWriter for column's layout in memory | ||
*/ | ||
public class LongArrayFrameColumnReader extends NumericArrayFrameColumnReader | ||
{ | ||
public LongArrayFrameColumnReader(int columnNumber) | ||
{ | ||
super(FrameColumnWriters.TYPE_LONG_ARRAY, ColumnType.LONG_ARRAY, columnNumber); | ||
} | ||
|
||
@Override | ||
NumericArrayFrameColumn column(Frame frame, Memory memory, ColumnType columnType) | ||
{ | ||
return new LongArrayFrameColumn(frame, memory, columnType); | ||
} | ||
|
||
private static class LongArrayFrameColumn extends NumericArrayFrameColumn | ||
{ | ||
public LongArrayFrameColumn( | ||
Frame frame, | ||
Memory memory, | ||
ColumnType columnType | ||
) | ||
{ | ||
super(frame, memory, columnType); | ||
} | ||
|
||
@Override | ||
Number getElement(Memory memory, long rowDataOffset, int cumulativeIndex) | ||
{ | ||
return memory.getLong(LongMath.checkedAdd(rowDataOffset, (long) cumulativeIndex * Long.BYTES)); | ||
} | ||
} | ||
} |
Oops, something went wrong.