Skip to content

Commit

Permalink
fix fmt, clippy, rebase fixes, and small test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkMyCar committed Dec 5, 2024
1 parent 2c5063b commit 4a31692
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 26 deletions.
5 changes: 2 additions & 3 deletions misc/python/materialize/parallel_workload/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

import random
import threading
from collections.abc import Iterator, Sequence
from collections.abc import Iterator
from copy import copy
from enum import Enum

import psycopg
from pg8000.native import identifier, literal

from materialize.data_ingest.data_type import (
Expand Down Expand Up @@ -196,7 +195,7 @@ def create(self, exe: Executor) -> None:


class DBObject:
columns: Sequence[Column]
columns: list[Column]
lock: threading.Lock

def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,8 @@ impl Catalog {
.iter()
.map(|(id, _)| id)
.chain(new_global_expressions.iter().map(|(id, _)| id))
.filter_map(|id| self.get_entry_by_global_id(id).index())
.map(|index| index.on);
.map(|id| self.get_entry_by_global_id(id))
.filter_map(|entry| entry.index().map(|index| index.on));
let invalidate_ids = self.invalidate_for_index(ons);
expr_cache
.update(
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/src/catalog/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,9 @@ impl CatalogState {
/// Returns the [`RelationDesc`] for a [`GlobalId`], if the provided [`GlobalId`] refers to an
/// object that returns rows.
pub fn try_get_desc_by_global_id(&self, id: &GlobalId) -> Option<Cow<RelationDesc>> {
let entry = self.try_get_entry_by_global_id(&id)?;
let entry = self.try_get_entry_by_global_id(id)?;
let desc = match entry.item() {
CatalogItem::Table(table) => Cow::Owned(table.desc_for(&id)),
CatalogItem::Table(table) => Cow::Owned(table.desc_for(id)),
// TODO(alter_table): Support schema evolution on sources.
other => other.desc_opt(RelationVersionSelector::Latest)?,
};
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/src/coord/sequencer/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4775,7 +4775,8 @@ impl Coordinator {
} = plan;

// TODO(alter_table): Support allocating GlobalIds without a CatalogItemId.
let (_, new_global_id) = self.catalog.allocate_user_id().await?;
let id_ts = self.get_catalog_write_ts().await;
let (_, new_global_id) = self.catalog.allocate_user_id(id_ts).await?;
let ops = vec![catalog::Op::AlterAddColumn {
id: relation_id,
new_global_id,
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/src/optimize/dataflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<'a> DataflowBuilder<'a> {
let entry = self.catalog.get_entry(id);
match entry.item() {
CatalogItem::Table(table) => {
dataflow.import_source(*id, table.desc_for(&id).typ().clone(), monotonic);
dataflow.import_source(*id, table.desc_for(id).typ().clone(), monotonic);
}
CatalogItem::Source(source) => {
dataflow.import_source(*id, source.desc.typ().clone(), monotonic);
Expand Down
5 changes: 1 addition & 4 deletions src/sql/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,7 @@ pub trait CatalogItem {

/// Returns the [`CatalogCollectionItem`] for a specific version of this
/// [`CatalogItem`].
fn at_version(
&self,
version: RelationVersionSelector,
) -> Box<dyn CatalogCollectionItem>;
fn at_version(&self, version: RelationVersionSelector) -> Box<dyn CatalogCollectionItem>;

/// The latest version of this item, if it's version-able.
fn latest_version(&self) -> Option<RelationVersion>;
Expand Down
4 changes: 2 additions & 2 deletions src/sql/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,8 @@ impl<'a> NameResolver<'a> {
};
let alter_table_enabled = self.catalog.system_vars().enable_alter_table_add_column();
let version = match version {
// If there isn't a version specified, and this item supports
// versioning, track the latest.
// If there isn't a version specified, and this item supports versioning, track the
// latest.
None => match item.latest_version() {
// Only track the version of the referenced object, if the feature is enabled.
Some(v) if alter_table_enabled => RelationVersionSelector::Specific(v),
Expand Down
9 changes: 8 additions & 1 deletion src/sql/src/plan/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,14 @@ pub fn plan_create_table(

let create_sql = normalize::create_statement(scx, Statement::CreateTable(stmt.clone()))?;

let options = plan_table_options(scx, &desc, with_options.clone())?;
// Table options should only consider the original columns, since those
// were the only ones in scope when the table was created.
//
// TODO(alter_table): Will need to reconsider this when we support ALTERing
// the PARTITION BY columns.
let original_desc = desc.at_version(RelationVersionSelector::Specific(RelationVersion::root()));
let options = plan_table_options(scx, &original_desc, with_options.clone())?;

let compaction_window = options.iter().find_map(|o| {
#[allow(irrefutable_let_patterns)]
if let crate::plan::TableOption::RetainHistory(lcw) = o {
Expand Down
2 changes: 1 addition & 1 deletion src/sql/src/session/vars/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ feature_flags!(
name: enable_alter_table_add_column,
desc: "Enable ALTER TABLE ... ADD COLUMN ...",
default: false,
enable_for_item_parsing: true,
enable_for_item_parsing: false,
},
{
name: enable_graceful_cluster_reconfiguration,
Expand Down
6 changes: 4 additions & 2 deletions src/storage-controller/src/persist_handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ impl<T: Timestamp + Lattice + Codec64 + TimestampManipulation> TxnsTableWorker<T
tx,
} => {
async {
self.drop_handles(vec![existing_collection], forget_ts).await;
self.register(register_ts, vec![(new_collection, handle)]).await;
self.drop_handles(vec![existing_collection], forget_ts)
.await;
self.register(register_ts, vec![(new_collection, handle)])
.await;
}
.instrument(span)
.await;
Expand Down
1 change: 1 addition & 0 deletions src/testdrive/src/action/consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ async fn check_catalog_state(state: &State) -> Result<(), anyhow::Error> {
// first lines that differs and show context around it.
let diff = similar::TextDiff::from_lines(&memory_catalog, &disk_catalog)
.unified_diff()
.header("memory", "disk")
.context_radius(50)
.to_string()
.lines()
Expand Down
12 changes: 6 additions & 6 deletions test/legacy-upgrade/check-from-v0.126.0-alter-table.td
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
> SELECT * FROM alter_table_t1_v2 ORDER BY a DESC;
<null> <null>
600 orange
500 apple
400 world
500 apple
400 world
300 <null>
200 hello
200 hello
100 <null>

> SELECT * FROM alter_table_t1_mv2 ORDER BY a DESC;
<null> <null>
600 orange
500 apple
400 world
500 apple
400 world
300 <null>
200 hello
200 hello
100 <null>
1 change: 0 additions & 1 deletion test/sqllogictest/alter-table.slt
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,3 @@ DROP TABLE t2 CASCADE;
query TTIT
SELECT * FROM mz_internal.mz_comments;
----

0 comments on commit 4a31692

Please sign in to comment.