Skip to content

Add sequence support to the MariaDB database type, fixes #8525 - #9484

Open
vasipallyn wants to merge 2 commits into
apache:mainfrom
vasipallyn:8525-mariadb-sequences
Open

vasipallyn wants to merge 2 commits into
apache:mainfrom
vasipallyn:8525-mariadb-sequences

Conversation

@vasipallyn

Copy link
Copy Markdown

MariaDB has supported sequences natively since 10.3, but the MariaDB database type inherited MySQL's lack of sequence support, so sequences could not be listed, checked or used from Hop.

This change, in 'MariaDBDatabaseMeta':
reports sequence support,
lists the sequences of the current database from INFORMATION_SCHEMA.TABLES, where MariaDB stores them with 'TABLE_TYPE = 'SEQUENCE',

  • checks whether a sequence exists in the current database, or in the given database for a schema-qualified (backtick-quoted) name such as "sales.order_seq"
  • uses 'NEXTVAL()' for the next value and 'LASTVAL()' for the current value.

'MariaDBSequenceAndReleaseSavePointTest', which asserted that MariaDB had no sequence support, now asserts the generated SQL, with extra cases for a schema-qualified name and for quote escaping. Formatting was checked with google-java-format 1.17. I could not run the full Maven build locally, so I am relying on the automated checks for that.

fixes #8525


MariaDB has supported sequences natively since 10.3, but the MariaDB
database type inherited MySQL's lack of sequence support, so sequences
could not be listed, checked or used from Hop.

- Report sequence support.
- List sequences of the current database from
  INFORMATION_SCHEMA.TABLES, where MariaDB stores them with
  TABLE_TYPE = 'SEQUENCE'.
- Check existence in the current database, or in the given database
  for a schema-qualified (backtick-quoted) name.
- Use NEXTVAL() for the next value and LASTVAL() for the current one.

@bamaer bamaer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vasipallyn, this looks good. We built the PR, ran the MariaDB plugin tests, and checked the generated SQL (list, exists with and without a schema, NEXTVAL, LASTVAL) against MariaDB 10.11. All of it works. One thing to fix, inline.


/** MariaDB supports sequences natively since 10.3, unlike MySQL. */
@Override
public boolean isSupportsSequences() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix

With sequences enabled, the SQL button in Dimension lookup and Combination lookup now generates a CREATE SEQUENCE for MariaDB. They pass max value -1 ("no maximum"), and since MariaDB doesn't report a no-max-value option, the statement ends in MAXVALUE -1. MariaDB rejects it:

ERROR 4085 (HY000): Sequence 'hop.dim_seq' has out of range value for options

MariaDB accepts NOMAXVALUE, which BaseDatabaseMeta.getSequenceNoMaxValueOption() already returns, so this override is enough:

@Override
public boolean isSupportsSequenceNoMaxValueOption() {
  return true;
}

We tried it: the generated DDL ends in NOMAXVALUE, runs on MariaDB 10.11, and NEXTVAL returns 1. An assertion on isSupportsSequenceNoMaxValueOption() in MariaDBSequenceAndReleaseSavePointTest would cover it.

…8525

The SQL button of Dimension lookup and Combination lookup generates
CREATE SEQUENCE with max value -1 ("no maximum"). MariaDB rejects
MAXVALUE -1 with "out of range value for options", but accepts
NOMAXVALUE, so report support for the no-max-value option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add support for sequences in MariaDB

2 participants