diff --git a/.github/workflows/mysql-copy-tests.yml b/.github/workflows/mysql-copy-tests.yml index e862686..580b94b 100644 --- a/.github/workflows/mysql-copy-tests.yml +++ b/.github/workflows/mysql-copy-tests.yml @@ -14,6 +14,8 @@ jobs: image: mysql:lts env: MYSQL_ROOT_PASSWORD: root + ports: + - 13306:3306 options: >- --health-cmd="mysqladmin ping" --health-interval=10s @@ -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 ( @@ -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 " diff --git a/catalog/database.go b/catalog/database.go index fd639ee..96f1f10 100644 --- a/catalog/database.go +++ b/catalog/database.go @@ -73,10 +73,21 @@ 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 } } @@ -84,7 +95,7 @@ func (d *Database) tablesInsensitive(ctx *sql.Context, pattern string) ([]*Table } 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) } diff --git a/catalog/table.go b/catalog/table.go index 49ee41a..d54339e 100644 --- a/catalog/table.go +++ b/catalog/table.go @@ -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) }