Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyang01 committed Dec 27, 2024
1 parent 8d13655 commit 3dcda64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/mysql-copy-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
image: mysql:lts
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 13306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
Expand Down Expand Up @@ -50,7 +52,7 @@ jobs:
- name: Setup test data in source MySQL
run: |
mysqlsh -hsource -uroot -proot --sql -e "
mysqlsh -hlocalhost -P13306 -uroot -proot --sql -e "
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE users (
Expand Down Expand Up @@ -79,13 +81,17 @@ jobs:
- name: Run copy-instance test
run: |
mysqlsh -hsource -uroot -proot \
# Set local_infile to true to allow loading data from files
mysqlsh -uroot --no-password --sql -e "SET GLOBAL local_infile = 1;"
# Copy the data from source MySQL to MyDuck
mysqlsh -hlocalhost -P13306 -uroot -proot \
-- util copy-instance "mysql://root:@127.0.0.1:3306" \
--users false --ignore-version true
# Verify the data was copied
for table in users items; do
mysqlsh -hsource -uroot -proot --sql -e "
mysqlsh -hlocalhost -P13306 -uroot -proot --sql -e "
SELECT * FROM testdb.$table ORDER BY id;
" | tee source_data_$table.tsv
mysqlsh -uroot --no-password --sql -e "
Expand Down
13 changes: 12 additions & 1 deletion catalog/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,29 @@ func (d *Database) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Ta
func (d *Database) tablesInsensitive(ctx *sql.Context, pattern string) ([]*Table, error) {
tables, err := d.findTables(ctx, pattern)
if err != nil {
ctx.GetLogger().WithFields(logrus.Fields{
"catalog": d.catalog,
"database": d.name,
"pattern": pattern,
}).WithError(err).Error("Failed to find tables")
return nil, err
}
for _, t := range tables {
if err := t.withSchema(ctx); err != nil {
ctx.GetLogger().WithFields(logrus.Fields{
"catalog": d.catalog,
"database": d.name,
"pattern": pattern,
"table": t.Name(),
}).WithError(err).Error("Failed to get table schema")
return nil, err
}
}
return tables, nil
}

func (d *Database) findTables(ctx *sql.Context, pattern string) ([]*Table, error) {
rows, err := adapter.QueryCatalog(ctx, "SELECT DISTINCT table_name, comment FROM duckdb_tables() where (database_name = ? and schema_name = ? and table_name ILIKE ?) or (database_name = 'temp' and schema_name = 'main' and table_name ILIKE ?)", d.catalog, d.name, pattern, pattern)
rows, err := adapter.QueryCatalog(ctx, "SELECT DISTINCT table_name, comment FROM duckdb_tables() WHERE (database_name = ? and schema_name = ? and table_name ILIKE ?) OR (temporary and table_name ILIKE ?)", d.catalog, d.name, pattern, pattern)
if err != nil {
return nil, ErrDuckDB.New(err)
}
Expand Down
5 changes: 3 additions & 2 deletions catalog/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,9 @@ func (t *Table) PeekNextAutoIncrementValue(ctx *sql.Context) (uint64, error) {
if !strings.Contains(err.Error(), "sequence is not yet defined in this session") {
return 0, ErrDuckDB.New(err)
}
// If the sequence has not been used yet, we can get the start value from the sequence
err = adapter.QueryRowCatalog(ctx, `SELECT start_value FROM duckdb_sequences() WHERE concat('"', schema_name, '"."', sequence_name, '"') = '`+t.comment.Meta.Sequence+`'`).Scan(&val)
// If the sequence has not been used yet, we can get the start value from the sequence.
// See getCreateSequence() for the sequence name format.
err = adapter.QueryRowCatalog(ctx, `SELECT start_value FROM duckdb_sequences() WHERE concat(schema_name, '."', sequence_name, '"') = '`+t.comment.Meta.Sequence+`'`).Scan(&val)
if err != nil {
return 0, ErrDuckDB.New(err)
}
Expand Down

0 comments on commit 3dcda64

Please sign in to comment.