Skip to content

Commit

Permalink
Merge branch 'naive-orderby' into constant-orderby
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkfish committed Jan 7, 2025
2 parents 6cee607 + 1c943f5 commit ffd1aa6
Show file tree
Hide file tree
Showing 67 changed files with 9,181 additions and 2,516 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
android:
name: Android
runs-on: ubuntu-latest
container: ubuntu:18.04
container: ubuntu:20.04
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feature' }}

strategy:
Expand Down
12 changes: 10 additions & 2 deletions scripts/run_tests_one_by_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def valid_timeout(value):

parser = argparse.ArgumentParser(description='Run tests one by one with optional flags.')
parser.add_argument('unittest_program', help='Path to the unittest program')
parser.add_argument('--no-exit', action='store_true', help='Do not exit after running tests')
parser.add_argument('--no-exit', action='store_true', help='Execute all tests, without stopping on first error')
parser.add_argument('--fast-fail', action='store_true', help='Terminate on first error')
parser.add_argument('--profile', action='store_true', help='Enable profiling')
parser.add_argument('--no-assertions', action='store_false', help='Disable assertions')
parser.add_argument('--time_execution', action='store_true', help='Measure and print the execution time of each test')
Expand Down Expand Up @@ -47,6 +48,13 @@ def valid_timeout(value):
# Access the arguments
unittest_program = args.unittest_program
no_exit = args.no_exit
fast_fail = args.fast_fail

if no_exit:
if fast_fail:
print("--no-exit and --fast-fail can't be combined")
exit(1)

profile = args.profile
assertions = args.no_assertions
time_execution = args.time_execution
Expand Down Expand Up @@ -87,7 +95,7 @@ def valid_timeout(value):
def fail():
global all_passed
all_passed = False
if not no_exit:
if fast_fail:
exit(1)


Expand Down
6 changes: 3 additions & 3 deletions scripts/sqllogictest/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ def compare_rows(a, b):
hash_compare_error = values[0] != hash_value

if hash_compare_error:
expected_result = self.result_label_map.get(query_label)
logger.wrong_result_hash(expected_result, self)
self.fail_query(query)
expected_result = runner.result_label_map.get(query_label)
# logger.wrong_result_hash(expected_result, self)
context.fail(query)

assert not hash_compare_error

Expand Down
92 changes: 67 additions & 25 deletions src/common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,72 @@ static bool CombineUnequalTypes(const LogicalType &left, const LogicalType &righ
return false;
}

template <class OP>
static bool CombineStructTypes(const LogicalType &left, const LogicalType &right, LogicalType &result) {
auto &left_children = StructType::GetChildTypes(left);
auto &right_children = StructType::GetChildTypes(right);

auto left_unnamed = StructType::IsUnnamed(left);
auto is_unnamed = left_unnamed || StructType::IsUnnamed(right);
child_list_t<LogicalType> child_types;

// At least one side is unnamed, so we attempt positional casting.
if (is_unnamed) {
if (left_children.size() != right_children.size()) {
// We can't cast, or create the super-set.
return false;
}

for (idx_t i = 0; i < left_children.size(); i++) {
LogicalType child_type;
if (!OP::Operation(left_children[i].second, right_children[i].second, child_type)) {
return false;
}
auto &child_name = left_unnamed ? right_children[i].first : left_children[i].first;
child_types.emplace_back(child_name, std::move(child_type));
}
result = LogicalType::STRUCT(child_types);
return true;
}

// Create a super-set of the STRUCT fields.
// First, create a name->index map of the right children.
case_insensitive_map_t<idx_t> right_children_map;
for (idx_t i = 0; i < right_children.size(); i++) {
auto &name = right_children[i].first;
right_children_map[name] = i;
}

for (idx_t i = 0; i < left_children.size(); i++) {
auto &left_child = left_children[i];
auto right_child_it = right_children_map.find(left_child.first);

if (right_child_it == right_children_map.end()) {
// We can directly put the left child.
child_types.emplace_back(left_child.first, left_child.second);
continue;
}

// We need to recurse to ensure the children have a maximum logical type.
LogicalType child_type;
auto &right_child = right_children[right_child_it->second];
if (!OP::Operation(left_child.second, right_child.second, child_type)) {
return false;
}
child_types.emplace_back(left_child.first, std::move(child_type));
right_children_map.erase(right_child_it);
}

// Add all remaining right children.
for (const auto &right_child_it : right_children_map) {
auto &right_child = right_children[right_child_it.second];
child_types.emplace_back(right_child.first, right_child.second);
}

result = LogicalType::STRUCT(child_types);
return true;
}

template <class OP>
static bool CombineEqualTypes(const LogicalType &left, const LogicalType &right, LogicalType &result) {
// Since both left and right are equal we get the left type as our type_id for checks
Expand Down Expand Up @@ -1059,31 +1125,7 @@ static bool CombineEqualTypes(const LogicalType &left, const LogicalType &right,
return true;
}
case LogicalTypeId::STRUCT: {
// struct: perform recursively on each child
auto &left_child_types = StructType::GetChildTypes(left);
auto &right_child_types = StructType::GetChildTypes(right);
bool left_unnamed = StructType::IsUnnamed(left);
auto any_unnamed = left_unnamed || StructType::IsUnnamed(right);
if (left_child_types.size() != right_child_types.size()) {
// child types are not of equal size, we can't cast
// return false
return false;
}
child_list_t<LogicalType> child_types;
for (idx_t i = 0; i < left_child_types.size(); i++) {
LogicalType child_type;
// Child names must be in the same order OR either one of the structs must be unnamed
if (!any_unnamed && !StringUtil::CIEquals(left_child_types[i].first, right_child_types[i].first)) {
return false;
}
if (!OP::Operation(left_child_types[i].second, right_child_types[i].second, child_type)) {
return false;
}
auto &child_name = left_unnamed ? right_child_types[i].first : left_child_types[i].first;
child_types.emplace_back(child_name, std::move(child_type));
}
result = LogicalType::STRUCT(child_types);
return true;
return CombineStructTypes<OP>(left, right, result);
}
case LogicalTypeId::UNION: {
auto left_member_count = UnionType::GetMemberCount(left);
Expand Down
54 changes: 30 additions & 24 deletions src/common/types/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ UnifiedVectorFormat &UnifiedVectorFormat::operator=(UnifiedVectorFormat &&other)
return *this;
}

Vector::Vector(LogicalType type_p, bool create_data, bool zero_data, idx_t capacity)
Vector::Vector(LogicalType type_p, bool create_data, bool initialize_to_zero, idx_t capacity)
: vector_type(VectorType::FLAT_VECTOR), type(std::move(type_p)), data(nullptr), validity(capacity) {
if (create_data) {
Initialize(zero_data, capacity);
Initialize(initialize_to_zero, capacity);
}
}

Expand Down Expand Up @@ -306,7 +306,7 @@ void Vector::Slice(const SelectionVector &sel, idx_t count, SelCache &cache) {
}
}

void Vector::Initialize(bool zero_data, idx_t capacity) {
void Vector::Initialize(bool initialize_to_zero, idx_t capacity) {
auxiliary.reset();
validity.Reset();
auto &type = GetType();
Expand All @@ -325,7 +325,7 @@ void Vector::Initialize(bool zero_data, idx_t capacity) {
if (type_size > 0) {
buffer = VectorBuffer::CreateStandardVector(type, capacity);
data = buffer->GetData();
if (zero_data) {
if (initialize_to_zero) {
memset(data, 0, capacity * type_size);
}
}
Expand Down Expand Up @@ -1374,10 +1374,10 @@ void Vector::Deserialize(Deserializer &deserializer, idx_t count) {
}

void Vector::SetVectorType(VectorType vector_type_p) {
this->vector_type = vector_type_p;
vector_type = vector_type_p;
auto physical_type = GetType().InternalType();
if (TypeIsConstantSize(physical_type) &&
(GetVectorType() == VectorType::CONSTANT_VECTOR || GetVectorType() == VectorType::FLAT_VECTOR)) {
auto flat_or_const = GetVectorType() == VectorType::CONSTANT_VECTOR || GetVectorType() == VectorType::FLAT_VECTOR;
if (TypeIsConstantSize(physical_type) && flat_or_const) {
auxiliary.reset();
}
if (vector_type == VectorType::CONSTANT_VECTOR && physical_type == PhysicalType::STRUCT) {
Expand Down Expand Up @@ -1782,23 +1782,29 @@ void Vector::DebugShuffleNestedVector(Vector &vector, idx_t count) {
void FlatVector::SetNull(Vector &vector, idx_t idx, bool is_null) {
D_ASSERT(vector.GetVectorType() == VectorType::FLAT_VECTOR);
vector.validity.Set(idx, !is_null);
if (is_null) {
auto &type = vector.GetType();
auto internal_type = type.InternalType();
if (internal_type == PhysicalType::STRUCT) {
// set all child entries to null as well
auto &entries = StructVector::GetEntries(vector);
for (auto &entry : entries) {
FlatVector::SetNull(*entry, idx, is_null);
}
} else if (internal_type == PhysicalType::ARRAY) {
// set the child element in the array to null as well
auto &child = ArrayVector::GetEntry(vector);
auto array_size = ArrayType::GetSize(type);
auto child_offset = idx * array_size;
for (idx_t i = 0; i < array_size; i++) {
FlatVector::SetNull(child, child_offset + i, is_null);
}
if (!is_null) {
return;
}

auto &type = vector.GetType();
auto internal_type = type.InternalType();

// Set all child entries to NULL.
if (internal_type == PhysicalType::STRUCT) {
auto &entries = StructVector::GetEntries(vector);
for (auto &entry : entries) {
FlatVector::SetNull(*entry, idx, is_null);
}
return;
}

// Set all child entries to NULL.
if (internal_type == PhysicalType::ARRAY) {
auto &child = ArrayVector::GetEntry(vector);
auto array_size = ArrayType::GetSize(type);
auto child_offset = idx * array_size;
for (idx_t i = 0; i < array_size; i++) {
FlatVector::SetNull(child, child_offset + i, is_null);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/execution/physical_plan/plan_cte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalMaterializ
auto right = CreatePlan(*op.children[1]);

unique_ptr<PhysicalCTE> cte;
cte = make_uniq<PhysicalCTE>(op.ctename, op.table_index, op.children[1]->types, std::move(left), std::move(right),
cte = make_uniq<PhysicalCTE>(op.ctename, op.table_index, right->types, std::move(left), std::move(right),
op.estimated_cardinality);
cte->working_table = working_table;
cte->cte_scans = materialized_ctes[op.table_index];
Expand Down
Loading

0 comments on commit ffd1aa6

Please sign in to comment.