Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1016469-Update-Javadocs-With-missing-…
Browse files Browse the repository at this point in the history
…comments
  • Loading branch information
sfc-gh-ext-simba-jf authored Oct 23, 2024
2 parents 3e0678b + 323fb54 commit 34c6737
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -23,7 +22,7 @@
import org.junit.experimental.categories.Category;

@Category(TestCategoryOthers.class)
public class DatabaseMetaDataResultsetIT extends BaseJDBCTest {
public class DatabaseMetaDataResultsetIT extends BaseJDBCWithSharedConnectionIT {
private static final int columnCount = 9;
private static final int INT_DATA = 1;
private static final String TEXT_DATA = "TEST";
Expand Down Expand Up @@ -98,8 +97,7 @@ public void testRowIndex() throws SQLException {
}

private ResultSet getResultSet(boolean doNext) throws SQLException {
Connection con = getConnection();
Statement st = con.createStatement();
Statement st = connection.createStatement();
ResultSet resultSet =
new SnowflakeDatabaseMetaDataResultSet(columnNames, columnTypeNames, columnTypes, rows, st);
if (doNext) {
Expand Down
32 changes: 12 additions & 20 deletions src/test/java/net/snowflake/client/jdbc/MultiStatementLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import net.snowflake.client.category.TestCategoryStatement;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -24,21 +24,19 @@
* both the latest and oldest supported driver run the tests.
*/
@Category(TestCategoryStatement.class)
public class MultiStatementLatestIT extends BaseJDBCTest {
public class MultiStatementLatestIT extends BaseJDBCWithSharedConnectionIT {
protected static String queryResultFormat = "json";

public static Connection getConnection() throws SQLException {
Connection conn = BaseJDBCTest.getConnection();
try (Statement stmt = conn.createStatement()) {
@Before
public void setQueryResultFormat() throws SQLException {
try (Statement stmt = connection.createStatement()) {
stmt.execute("alter session set jdbc_query_result_format = '" + queryResultFormat + "'");
}
return conn;
}

@Test
public void testMultiStmtExecute() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 3);
String multiStmtQuery =
"create or replace temporary table test_multi (cola int);\n"
Expand Down Expand Up @@ -74,8 +72,7 @@ public void testMultiStmtExecute() throws SQLException {

@Test
public void testMultiStmtTransaction() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
try {
statement.execute(
"create or replace table test_multi_txn(c1 number, c2 string)" + " as select 10, 'z'");
Expand Down Expand Up @@ -120,8 +117,7 @@ public void testMultiStmtTransaction() throws SQLException {

@Test
public void testMultiStmtExecuteUpdate() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
String multiStmtQuery =
"create or replace temporary table test_multi (cola int);\n"
+ "insert into test_multi VALUES (1), (2);\n"
Expand Down Expand Up @@ -157,8 +153,7 @@ public void testMultiStmtExecuteUpdate() throws SQLException {

@Test
public void testMultiStmtTransactionRollback() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
try {
statement.execute(
"create or replace table test_multi_txn_rb(c1 number, c2 string)"
Expand Down Expand Up @@ -207,8 +202,7 @@ public void testMultiStmtTransactionRollback() throws SQLException {

@Test
public void testMultiStmtExecuteQuery() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
String multiStmtQuery =
"select 1;\n"
+ "create or replace temporary table test_multi (cola int);\n"
Expand Down Expand Up @@ -254,8 +248,7 @@ public void testMultiStmtExecuteQuery() throws SQLException {

@Test
public void testMultiStmtUpdateCount() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
statement.unwrap(SnowflakeStatement.class).setParameter("MULTI_STATEMENT_COUNT", 2);
boolean isResultSet =
statement.execute(
Expand All @@ -280,8 +273,7 @@ public void testMultiStmtUpdateCount() throws SQLException {
/** Test use of anonymous blocks (SNOW-758262) */
@Test
public void testAnonymousBlocksUse() throws SQLException {
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try (Statement statement = connection.createStatement()) {
statement.execute("create or replace table tab758262(c1 number)");
// Test anonymous block with multistatement
int multistatementcount = 2;
Expand Down
188 changes: 88 additions & 100 deletions src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.TestUtil;
import net.snowflake.client.category.TestCategoryOthers;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

/** Test OpenGroup CLI */
@Category(TestCategoryOthers.class)
public class OpenGroupCLIFuncIT extends BaseJDBCTest {
public static Connection getConnection() throws SQLException {
Connection connection = AbstractDriverIT.getConnection();
public class OpenGroupCLIFuncIT extends BaseJDBCWithSharedConnectionIT {

@BeforeClass
public static void setSessionTimezone() throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.execute(
"alter session set "
Expand All @@ -31,114 +32,101 @@ public static Connection getConnection() throws SQLException {
+ "TIMESTAMP_LTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
+ "TIMESTAMP_NTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM'");
}
return connection;
}

@Test
public void testStringFunction() throws SQLException {
try (Connection connection = getConnection()) {
testFunction(connection, "select {fn ASCII('snowflake')}", "115");
testFunction(connection, "select {fn CHAR(115)}", "s");
testFunction(connection, "select {fn CONCAT('snow', 'flake')}", "snowflake");
// DIFFERENCE is not supported
// testFunction(connection, "select {fn DIFFERENCE('snow', 'flake')}", "snowflake");
testFunction(connection, "select {fn INSERT('snowflake', 2, 3, 'insert')}", "sinsertflake");
testFunction(connection, "select {fn LCASE('SNOWflake')}", "snowflake");
testFunction(connection, "select {fn LEFT('snowflake', 4)}", "snow");
testFunction(connection, "select {fn LENGTH(' snowflake ')}", "11");
testFunction(connection, "select {fn LOCATE('str', 'strstrstr', 2)}", "4");
testFunction(connection, "select {fn LTRIM(' snowflake ')}", "snowflake ");
testFunction(connection, "select {fn REPEAT('snow', 3)}", "snowsnowsnow");
testFunction(connection, "select {fn REPLACE('snowssnowsn', 'sn', 'aa')}", "aaowsaaowaa");
testFunction(connection, "select {fn RIGHT('snowflake', 5)}", "flake");
testFunction(connection, "select {fn RTRIM(' snowflake ')}", " snowflake");
// SOUNDEX is not supported
// testFunction(connection, "select {fn SOUNDEX('snowflake')}", " snowflake");
testFunction(connection, "select {fn SPACE(4)}", " ");
testFunction(connection, "select {fn SUBSTRING('snowflake', 2, 3)}", "now");
testFunction(connection, "select {fn UCASE('snowflake')}", "SNOWFLAKE");
}
testFunction(connection, "select {fn ASCII('snowflake')}", "115");
testFunction(connection, "select {fn CHAR(115)}", "s");
testFunction(connection, "select {fn CONCAT('snow', 'flake')}", "snowflake");
// DIFFERENCE is not supported
// testFunction(connection, "select {fn DIFFERENCE('snow', 'flake')}", "snowflake");
testFunction(connection, "select {fn INSERT('snowflake', 2, 3, 'insert')}", "sinsertflake");
testFunction(connection, "select {fn LCASE('SNOWflake')}", "snowflake");
testFunction(connection, "select {fn LEFT('snowflake', 4)}", "snow");
testFunction(connection, "select {fn LENGTH(' snowflake ')}", "11");
testFunction(connection, "select {fn LOCATE('str', 'strstrstr', 2)}", "4");
testFunction(connection, "select {fn LTRIM(' snowflake ')}", "snowflake ");
testFunction(connection, "select {fn REPEAT('snow', 3)}", "snowsnowsnow");
testFunction(connection, "select {fn REPLACE('snowssnowsn', 'sn', 'aa')}", "aaowsaaowaa");
testFunction(connection, "select {fn RIGHT('snowflake', 5)}", "flake");
testFunction(connection, "select {fn RTRIM(' snowflake ')}", " snowflake");
// SOUNDEX is not supported
// testFunction(connection, "select {fn SOUNDEX('snowflake')}", " snowflake");
testFunction(connection, "select {fn SPACE(4)}", " ");
testFunction(connection, "select {fn SUBSTRING('snowflake', 2, 3)}", "now");
testFunction(connection, "select {fn UCASE('snowflake')}", "SNOWFLAKE");
}

@Test
public void testDateTimeFunction() throws SQLException {
try (Connection connection = getConnection()) {
// testFunction(connection, "select {fn CURDATE()}","");
// testFunction(connection, "select {fn CURTIME()}","");
testFunction(connection, "select {fn DAYNAME('2016-5-25')}", "Wed");
testFunction(connection, "select {fn DAYOFMONTH(to_date('2016-5-25'))}", "25");
testFunction(connection, "select {fn DAYOFWEEK(to_date('2016-5-25'))}", "3");
testFunction(connection, "select {fn DAYOFYEAR(to_date('2016-5-25'))}", "146");
testFunction(connection, "select {fn HOUR(to_timestamp('2016-5-25 12:34:56.789789'))}", "12");
testFunction(
connection, "select {fn MINUTE(to_timestamp('2016-5-25 12:34:56.789789'))}", "34");
testFunction(connection, "select {fn MONTH(to_date('2016-5-25'))}", "5");
testFunction(connection, "select {fn MONTHNAME(to_date('2016-5-25'))}", "May");
// testFunction(connection, "select {fn NOW()}", "May");
testFunction(connection, "select {fn QUARTER(to_date('2016-5-25'))}", "2");
testFunction(
connection, "select {fn SECOND(to_timestamp('2016-5-25 12:34:56.789789'))}", "56");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_FRAC_SECOND, 1000, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_SECOND, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 12:34:57 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_MINUTE, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 12:35:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_HOUR, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 13:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_DAY, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Thu, 26 May 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_MONTH, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Sat, 25 Jun 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_QUARTER, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Thu, 25 Aug 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_YEAR, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Thu, 25 May 2017 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, "
+ "to_timestamp('2016-5-25 12:34:56.789789'), to_timestamp('2016-5-25 12:34:57.789789'))}",
"1");
testFunction(connection, "select {fn WEEK(to_timestamp('2016-5-25 12:34:56.789789'))}", "21");
testFunction(
connection, "select {fn YEAR(to_timestamp('2016-5-25 12:34:56.789789'))}", "2016");
}
// testFunction(connection, "select {fn CURDATE()}","");
// testFunction(connection, "select {fn CURTIME()}","");
testFunction(connection, "select {fn DAYNAME('2016-5-25')}", "Wed");
testFunction(connection, "select {fn DAYOFMONTH(to_date('2016-5-25'))}", "25");
testFunction(connection, "select {fn DAYOFWEEK(to_date('2016-5-25'))}", "3");
testFunction(connection, "select {fn DAYOFYEAR(to_date('2016-5-25'))}", "146");
testFunction(connection, "select {fn HOUR(to_timestamp('2016-5-25 12:34:56.789789'))}", "12");
testFunction(connection, "select {fn MINUTE(to_timestamp('2016-5-25 12:34:56.789789'))}", "34");
testFunction(connection, "select {fn MONTH(to_date('2016-5-25'))}", "5");
testFunction(connection, "select {fn MONTHNAME(to_date('2016-5-25'))}", "May");
// testFunction(connection, "select {fn NOW()}", "May");
testFunction(connection, "select {fn QUARTER(to_date('2016-5-25'))}", "2");
testFunction(connection, "select {fn SECOND(to_timestamp('2016-5-25 12:34:56.789789'))}", "56");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_FRAC_SECOND, 1000, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_SECOND, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 12:34:57 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_MINUTE, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 12:35:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_HOUR, 1, " + "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Wed, 25 May 2016 13:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_DAY, 1, " + "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Thu, 26 May 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_MONTH, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Sat, 25 Jun 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_QUARTER, 1, "
+ "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Thu, 25 Aug 2016 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPADD(SQL_TSI_YEAR, 1, " + "to_timestamp('2016-5-25 12:34:56.789789'))}",
"Thu, 25 May 2017 12:34:56 -0700");
testFunction(
connection,
"select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, "
+ "to_timestamp('2016-5-25 12:34:56.789789'), to_timestamp('2016-5-25 12:34:57.789789'))}",
"1");
testFunction(connection, "select {fn WEEK(to_timestamp('2016-5-25 12:34:56.789789'))}", "21");
testFunction(connection, "select {fn YEAR(to_timestamp('2016-5-25 12:34:56.789789'))}", "2016");
}

@Test
public void testSystemFunctions() throws SQLException {
try (Connection connection = getConnection()) {
testFunction(connection, "select {fn DATABASE()}", connection.getCatalog());
testFunction(connection, "select {fn IFNULL(NULL, 1)}", "1");
testFunction(
connection,
"select {fn USER()}",
TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase());
}
testFunction(connection, "select {fn DATABASE()}", connection.getCatalog());
testFunction(connection, "select {fn IFNULL(NULL, 1)}", "1");
testFunction(
connection,
"select {fn USER()}",
TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase());
}

static void testFunction(Connection connection, String sql, String expected) throws SQLException {
Expand Down

This file was deleted.

Loading

0 comments on commit 34c6737

Please sign in to comment.