Skip to content

Commit

Permalink
SVV_TABLES integration test
Browse files Browse the repository at this point in the history
Added svv_tables.sql for querying  data
Added SvvTablesTest test
  • Loading branch information
gregflack committed Jun 22, 2022
1 parent 7570429 commit 04d5310
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 450 deletions.
4 changes: 4 additions & 0 deletions dumper-integration-tests/redshift-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ dependencies {
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.apache.commons:commons-collections4:4.4'
implementation 'com.opencsv:opencsv:5.6'
implementation 'com.google.truth:truth:1.1.3'
implementation 'com.google.truth.extensions:truth-java8-extension:1.1.3'

implementation 'com.amazon.redshift:redshift-jdbc42:2.1.0.7'
annotationProcessor 'com.google.auto.value:auto-value:1.9'
compileOnly 'com.google.auto.value:auto-value-annotations:1.9'
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
*/
package com.google.edwmigration.dumper.jdbc;

import static com.google.edwmigration.dumper.base.TestConstants.TRAILING_SPACES_REGEX;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.ArrayList;
import java.util.List;

/**
* A helper class for checking Null values returned by executing SELECT request against a database.
*/
public final class JdbcUtil {

private JdbcUtil() {}
private JdbcUtil() {
}

/**
* @param rs A row with SELECT results.
Expand All @@ -39,67 +36,28 @@ private JdbcUtil() {}
*/
public static String getStringNotNull(ResultSet rs, String column) throws SQLException {
String string = rs.getString(column);
return rs.wasNull() ? "" : TRAILING_SPACES_REGEX.matcher(string).replaceFirst("");
return rs.wasNull() ? "" : string;
}

/**
* @param rs A row with SELECT results.
* @param column Database column name.
* @return int or 0 if null.
*/
public static int getIntNotNull(ResultSet rs, String column) throws SQLException {
int intValue = rs.getInt(column);
return rs.wasNull() ? 0 : intValue;
}

/**
* @param rs A row with SELECT results.
* @param column Database column name.
* @return long or 0L if null.
*/
public static long getLongNotNull(ResultSet rs, String column) throws SQLException {
long longValue = rs.getLong(column);
return rs.wasNull() ? 0L : longValue;
}

/**
* @param rs A row with SELECT results.
* @param column Database column name.
* @return byte[] or empty byte[] if null.
*/
public static byte[] getBytesNotNull(ResultSet rs, String column) throws SQLException {
try {
byte[] bytesValue = rs.getBytes(column);
return rs.wasNull() ? new byte[0] : bytesValue;
} catch (SQLException e) {
BigDecimal bigDecimal = rs.getBigDecimal(column);
return rs.wasNull() ? new byte[0] : bigDecimal.toBigInteger().toByteArray();
}
}

/**
* @param rs A row with SELECT results.
* @param column Database column name.
* @return double or 0.0 if null.
* @param columnIndex Database column index.
* @return String or an empty string if null.
*/
public static double getDoubleNotNull(ResultSet rs, String column) throws SQLException {
double doubleValue = rs.getDouble(column);
return rs.wasNull() ? 0.0 : doubleValue;
public static String getStringNotNull(ResultSet rs, int columnIndex) throws SQLException {
String string = rs.getString(columnIndex);
return rs.wasNull() ? "" : string;
}

/**
* @param rs A row with SELECT results.
* @param column Database column name.
* @return long or 0L if null.
* @param rsmd Metadata of the executed SQL query.
* @return List of column names.
*/
public static long getTimestampNotNull(ResultSet rs, String column) throws SQLException {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
Timestamp timestamp = rs.getTimestamp(column, cal);
if (rs.wasNull()) {
return 0L;
public static List<String> getDbColumnNames(ResultSetMetaData rsmd) throws SQLException {
List<String> columnNames = new ArrayList<>();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
columnNames.add(rsmd.getColumnName(i));
}
return Timestamp.from(
ZonedDateTime.of(timestamp.toLocalDateTime(), cal.getTimeZone().toZoneId()).toInstant())
.getTime();
return columnNames;
}
}
}

This file was deleted.

Loading

0 comments on commit 04d5310

Please sign in to comment.