Skip to content

Commit

Permalink
add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
quodlibetor committed Aug 11, 2021
1 parent ec0ae38 commit 780688f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/coord/src/catalog/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use sql::ast::visit_mut::{self, VisitMut};
use sql::ast::{
AvroSchema, CreateIndexStatement, CreateSinkStatement, CreateSourceFormat,
CreateSourceStatement, CreateTableStatement, CreateTypeStatement, CreateViewStatement,
CsrConnector, DataType, Format, Function, Ident, Raw, RawName, SqlOption, Statement,
TableFactor, UnresolvedObjectName, Value, ViewDefinition, WithOption, WithOptionValue,
CsrConnector, CsvColumns, DataType, Format, Function, Ident, Raw, RawName, SqlOption,
Statement, TableFactor, UnresolvedObjectName, Value, ViewDefinition, WithOption,
WithOptionValue,
};
use sql::plan::resolve_names_stmt;

Expand Down Expand Up @@ -58,8 +59,10 @@ pub(crate) fn migrate(catalog: &mut Catalog) -> Result<(), anyhow::Error> {
ast_rewrite_type_references_0_6_1(stmt)?;
ast_use_pg_catalog_0_7_1(stmt)?;
ast_insert_default_confluent_wire_format_0_7_1(stmt)?;
ast_rewrite_csv_column_aliases_0_9_1(stmt)?;
Ok(())
})?;

// Then, load up a temporary catalog with the rewritten items, and perform
// some transformations that require introspecting the catalog. These
// migrations are *weird*: they're rewriting the catalog while looking at
Expand Down Expand Up @@ -337,6 +340,34 @@ fn ast_rewrite_type_references_0_6_1(
Ok(())
}

fn ast_rewrite_csv_column_aliases_0_9_1(
stmt: &mut sql::ast::Statement<Raw>,
) -> Result<(), anyhow::Error> {
let (col_names, format) = if let Statement::CreateSource(CreateSourceStatement {
col_names,
format: CreateSourceFormat::Bare(format),
..
}) = stmt
{
(col_names, format)
} else {
return Ok(());
};

// only do anything if we have empty header names for a csv source
if let Format::Csv {
columns: CsvColumns::Header { names },
..
} = format
{
if names.is_empty() {
names.extend_from_slice(col_names)
}
};

Ok(())
}

// ****************************************************************************
// Semantic migrations -- Weird migrations that require access to the catalog
// ****************************************************************************
Expand Down

0 comments on commit 780688f

Please sign in to comment.