2021-04-20 15:55:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/ColumnWithTypeAndName.h>
|
2021-04-27 12:49:58 +00:00
|
|
|
#include <Core/ColumnsWithTypeAndName.h>
|
2021-04-20 15:55:33 +00:00
|
|
|
#include <Core/Field.h>
|
|
|
|
#include <Common/PODArray.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-04-27 12:49:58 +00:00
|
|
|
|
2021-05-18 13:05:55 +00:00
|
|
|
/// Expand data by mask. After expanding data will satisfy the following: if we filter data
|
2021-06-08 13:55:07 +00:00
|
|
|
/// by given mask, we get initial data. In places where mask[i] = 0 we insert default value.
|
2021-06-07 10:55:55 +00:00
|
|
|
/// If inverted is true, we will work with inverted mask. This function is used in implementations of
|
2021-05-18 13:05:55 +00:00
|
|
|
/// expand() method in IColumn interface.
|
|
|
|
template <typename T>
|
2021-06-07 10:55:55 +00:00
|
|
|
void expandDataByMask(PaddedPODArray<T> & data, const PaddedPODArray<UInt8> & mask, bool inverted);
|
2021-05-18 13:05:55 +00:00
|
|
|
|
2021-06-07 10:55:55 +00:00
|
|
|
struct MaskInfo
|
|
|
|
{
|
2021-06-22 16:21:23 +00:00
|
|
|
bool has_ones;
|
|
|
|
bool has_zeros;
|
2021-06-07 10:55:55 +00:00
|
|
|
};
|
|
|
|
|
2021-08-10 11:31:15 +00:00
|
|
|
/// The next functions are used to extract UInt8 mask from a column,
|
2021-06-22 16:21:23 +00:00
|
|
|
/// filtered by some condition (mask). We will use value from a column
|
|
|
|
/// only when value in condition is 1. Column should satisfy the
|
|
|
|
/// condition: sum(mask) = column.size() or mask.size() = column.size().
|
2021-08-10 11:31:15 +00:00
|
|
|
/// You can set flag 'inverted' to use inverted values
|
2021-06-22 16:21:23 +00:00
|
|
|
/// from a column. You can also determine value that will be used when
|
|
|
|
/// column value is Null (argument null_value).
|
|
|
|
|
|
|
|
MaskInfo extractMask(
|
2021-08-10 11:31:15 +00:00
|
|
|
PaddedPODArray<UInt8> & mask,
|
2021-06-22 16:21:23 +00:00
|
|
|
const ColumnPtr & column,
|
|
|
|
UInt8 null_value = 0);
|
|
|
|
|
2021-08-10 11:31:15 +00:00
|
|
|
MaskInfo extractInvertedMask(
|
2021-06-22 16:21:23 +00:00
|
|
|
PaddedPODArray<UInt8> & mask,
|
2021-05-17 16:06:46 +00:00
|
|
|
const ColumnPtr & column,
|
2021-06-22 16:21:23 +00:00
|
|
|
UInt8 null_value = 0);
|
|
|
|
|
2021-08-10 11:31:15 +00:00
|
|
|
/// The same as extractMask, but fills
|
2021-06-22 16:21:23 +00:00
|
|
|
/// nulls so that nulls[i] = 1 when column[i] = Null.
|
2021-08-10 11:31:15 +00:00
|
|
|
MaskInfo extractMask(
|
|
|
|
PaddedPODArray<UInt8> & mask,
|
|
|
|
const ColumnPtr & column,
|
|
|
|
PaddedPODArray<UInt8> * nulls,
|
|
|
|
UInt8 null_value = 0);
|
|
|
|
|
|
|
|
MaskInfo extractInvertedMask(
|
2021-06-22 16:21:23 +00:00
|
|
|
PaddedPODArray<UInt8> & mask,
|
|
|
|
const ColumnPtr & column,
|
|
|
|
PaddedPODArray<UInt8> * nulls,
|
|
|
|
UInt8 null_value = 0);
|
2021-06-07 10:55:55 +00:00
|
|
|
|
|
|
|
/// Inplace inversion.
|
2021-08-10 11:31:15 +00:00
|
|
|
void inverseMask(PaddedPODArray<UInt8> & mask, MaskInfo & mask_info);
|
2021-04-20 15:55:33 +00:00
|
|
|
|
2021-05-18 13:05:55 +00:00
|
|
|
/// If given column is lazy executed argument (ColumnFunction with isShortCircuitArgument() = true),
|
2021-06-07 10:55:55 +00:00
|
|
|
/// filter it by mask and then reduce. If inverted is true, we will work with inverted mask.
|
2021-08-10 11:31:15 +00:00
|
|
|
void maskedExecute(ColumnWithTypeAndName & column, const PaddedPODArray<UInt8> & mask, const MaskInfo & mask_info);
|
2021-04-27 12:49:58 +00:00
|
|
|
|
2021-06-07 10:55:55 +00:00
|
|
|
/// If given column is lazy executed argument, reduce it. If empty is true,
|
|
|
|
/// create an empty column with the execution result type.
|
|
|
|
void executeColumnIfNeeded(ColumnWithTypeAndName & column, bool empty = false);
|
2021-04-20 15:55:33 +00:00
|
|
|
|
2021-05-18 13:05:55 +00:00
|
|
|
/// Check if arguments contain lazy executed argument. If contain, return index of the last one,
|
|
|
|
/// otherwise return -1.
|
2021-12-20 11:49:05 +00:00
|
|
|
int checkShortCircuitArguments(const ColumnsWithTypeAndName & arguments);
|
2021-04-27 12:49:58 +00:00
|
|
|
|
2021-08-10 11:31:15 +00:00
|
|
|
void copyMask(const PaddedPODArray<UInt8> & from, PaddedPODArray<UInt8> & to);
|
2021-06-22 16:21:23 +00:00
|
|
|
|
2021-04-20 15:55:33 +00:00
|
|
|
}
|