Skip to content

Commit

Permalink
[PDI-13609] Database Dialect Sequence Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Tucker authored and Marc Batchelor committed Dec 8, 2015
1 parent 001a0ab commit b01a3cd
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 12 deletions.
5 changes: 5 additions & 0 deletions core/src/org/pentaho/di/core/database/AS400DatabaseMeta.java
Expand Up @@ -272,6 +272,11 @@ public boolean supportsSequences() {
return true;
}

@Override
public String getSQLListOfSequences() {
return "SELECT SEQNAME FROM SYSCAT.SEQUENCES";
}

/**
* Check if a sequence exists.
*
Expand Down
5 changes: 5 additions & 0 deletions core/src/org/pentaho/di/core/database/DB2DatabaseMeta.java
Expand Up @@ -357,6 +357,11 @@ public boolean supportsSequences() {
return true;
}

@Override
public String getSQLListOfSequences() {
return "SELECT SEQNAME FROM SYSCAT.SEQUENCES";
}

/**
* Check if a sequence exists.
*
Expand Down
Expand Up @@ -269,6 +269,11 @@ public String getSQLSequenceExists( String sequenceName ) {
return "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME = '" + sequenceName + "'";
}

@Override
public String getSQLListOfSequences() {
return "SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES";
}

/**
* Get the current value of a database sequence
*
Expand Down
Expand Up @@ -160,6 +160,11 @@ public String getSQLSequenceExists( String sequenceName ) {
return "SELECT relname AS sequence_name FROM sys_class WHERE relname = '" + sequenceName.toLowerCase() + "'";
}

@Override
public String getSQLListOfSequences() {
return "SELECT relname AS sequence_name FROM sys_class";
}

/**
* Generates the SQL statement to add a column to the specified table
*
Expand Down
Expand Up @@ -182,6 +182,11 @@ public String getSQLSequenceExists( String sequenceName ) {
return "SELECT seqname AS sequence_name from _v_sequence where seqname = '" + sequenceName.toLowerCase() + "'";
}

@Override
public String getSQLListOfSequences() {
return "SELECT seqname AS sequence_name from _v_sequence";
}

/**
* Generates the SQL statement to add a column to the specified table Note: Netezza does not allow adding columns to
* tables
Expand Down
Expand Up @@ -102,6 +102,11 @@ public boolean supportsSequences() {
return true;
}

@Override
public String getSQLListOfSequences() {
return "SELECT SEQUENCE_NAME FROM USER_SEQUENCES";
}

/**
* Check if a sequence exists.
*
Expand Down
10 changes: 10 additions & 0 deletions core/src/org/pentaho/di/core/database/VerticaDatabaseMeta.java
Expand Up @@ -300,6 +300,16 @@ public boolean supportsSequences() {
return true;
}

@Override
public String getSQLSequenceExists( String sequenceName ) {
return "SELECT sequence_name FROM sequences WHERE sequence_name = '" + sequenceName + "'";
}

@Override
public String getSQLListOfSequences() {
return "SELECT sequence_name FROM sequences";
}

/**
* Get the SQL to get the next value of a sequence. (Vertica version)
*
Expand Down
42 changes: 30 additions & 12 deletions test/org/pentaho/di/core/database/SequenceMetaTests.java
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -27,6 +27,7 @@
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.pentaho.di.core.Const;

public class SequenceMetaTests {

Expand All @@ -36,38 +37,45 @@ public void testSupport() {
// According to our Meta, Oracle, PostGres,
// Greenplum and Vertica support sequences
DatabaseInterface[] support = new DatabaseInterface[] {
new OracleDatabaseMeta(),
new OracleRDBDatabaseMeta(),
new VerticaDatabaseMeta(),
new PostgreSQLDatabaseMeta(),
new GreenplumDatabaseMeta(),
new AS400DatabaseMeta(),
new DB2DatabaseMeta(),
new GreenplumDatabaseMeta(),
new HypersonicDatabaseMeta(),
new KingbaseESDatabaseMeta(),
new NetezzaDatabaseMeta()
new NetezzaDatabaseMeta(),
new OracleDatabaseMeta(),
new OracleRDBDatabaseMeta(),
new PostgreSQLDatabaseMeta(),
new RedshiftDatabaseMeta(),
new VerticaDatabaseMeta(),
new Vertica5DatabaseMeta(),
};

// the rest of the database metas say they don't support sequences
DatabaseInterface[] doNotSupport = new DatabaseInterface[] {
new MySQLDatabaseMeta(),
new InfiniDbDatabaseMeta(),
new InfobrightDatabaseMeta(),
new CacheDatabaseMeta(),
new DbaseDatabaseMeta(),
new DerbyDatabaseMeta(),
new Exasol4DatabaseMeta(),
new ExtenDBDatabaseMeta(),
new ExtenDBDatabaseMeta(),
new FirebirdDatabaseMeta(),
new GenericDatabaseMeta(),
new GuptaDatabaseMeta(),
new H2DatabaseMeta(),
new InfiniDbDatabaseMeta(),
new InfobrightDatabaseMeta(),
new InformixDatabaseMeta(),
new IngresDatabaseMeta(),
new InterbaseDatabaseMeta(),
new KettleDatabaseMeta(),
new LucidDBDatabaseMeta(),
new MondrianNativeDatabaseMeta(),
new MonetDBDatabaseMeta(),
new MSAccessDatabaseMeta(),
new MSSQLServerDatabaseMeta(),
new MSSQLServerNativeDatabaseMeta(),
new MySQLDatabaseMeta(),
new NeoviewDatabaseMeta(),
new RemedyActionRequestSystemDatabaseMeta(),
new SAPDBDatabaseMeta(),
Expand All @@ -76,7 +84,8 @@ public void testSupport() {
new SybaseDatabaseMeta(),
new SybaseIQDatabaseMeta(),
new TeradataDatabaseMeta(),
new UniVerseDatabaseMeta()
new UniVerseDatabaseMeta(),
new VectorWiseDatabaseMeta()
};

for ( DatabaseInterface db : support ) {
Expand All @@ -89,10 +98,19 @@ public void testSupport() {
}

private static void assertSupports( DatabaseInterface db, boolean expected ) {
String dbType = db.getClass().getSimpleName();
if (expected) {
assertTrue( db.getClass().getSimpleName(), db.supportsSequences() );
assertTrue( dbType, db.supportsSequences() );
assertFalse( dbType + ": List of Sequences", Const.isEmpty( db.getSQLListOfSequences() ) );
assertFalse( dbType + ": Sequence Exists", Const.isEmpty( db.getSQLSequenceExists( "testSeq" ) ) );
assertFalse( dbType + ": Current Value", Const.isEmpty( db.getSQLCurrentSequenceValue( "testSeq" ) ) );
assertFalse( dbType + ": Next Value", Const.isEmpty( db.getSQLNextSequenceValue( "testSeq" ) ) );
} else {
assertFalse( db.getClass().getSimpleName(), db.supportsSequences() );
assertTrue( dbType + ": List of Sequences", Const.isEmpty( db.getSQLListOfSequences() ) );
assertTrue( dbType + ": Sequence Exists", Const.isEmpty( db.getSQLSequenceExists( "testSeq" ) ) );
assertTrue( dbType + ": Current Value", Const.isEmpty( db.getSQLCurrentSequenceValue( "testSeq" ) ) );
assertTrue( dbType + ": Next Value", Const.isEmpty( db.getSQLNextSequenceValue( "testSeq" ) ) );
}
}

Expand Down

0 comments on commit b01a3cd

Please sign in to comment.