net.snowflake.client.jdbc.SnowflakeConnectionV1 Java Examples
The following examples show how to use
net.snowflake.client.jdbc.SnowflakeConnectionV1.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnowflakeConnectionServiceV1.java From snowflake-kafka-connector with Apache License 2.0 | 6 votes |
@Override public void put(final String stageName, final String fileName, final String content) { InternalUtils.assertNotEmpty("stageName", stageName); SnowflakeConnectionV1 sfconn = (SnowflakeConnectionV1) conn; InputStream input = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); try { InternalUtils.backoffAndRetry(telemetry, () -> { sfconn.uploadStream(stageName, FileNameUtils.getPrefixFromFileName(fileName), input, FileNameUtils.removePrefixAndGZFromFileName(fileName), true); return true; }); } catch (Exception e) { throw SnowflakeErrors.ERROR_2003.getException(e); } logDebug("put file {} to stage {}", fileName, stageName); }
Example #2
Source File: SnowflakeConnectionServiceV1.java From snowflake-kafka-connector with Apache License 2.0 | 6 votes |
@Override public void putToTableStage(final String tableName, final String fileName, final byte[] content) { InternalUtils.assertNotEmpty("tableName", tableName); SnowflakeConnectionV1 sfconn = (SnowflakeConnectionV1) conn; InputStream input = new ByteArrayInputStream(content); try { InternalUtils.backoffAndRetry(telemetry, () -> { sfconn.uploadStream("%" + tableName, FileNameUtils.getPrefixFromFileName(fileName), input, FileNameUtils.removePrefixAndGZFromFileName(fileName), true); return true; } ); } catch (Exception e) { throw SnowflakeErrors.ERROR_2003.getException(e); } logInfo("put file: {} to table stage: {}", fileName, tableName); }
Example #3
Source File: ConnectionUtils.java From snowflake-kafka-connector with Apache License 2.0 | 6 votes |
private static void initConnection() { Properties testProps = getServerProps("test"); // Properties snowhouseProps = getServerProps("snowhouse"); try { testConn = new SnowflakeConnectionV1(testProps.getProperty(URL), testProps); // snowhouseConn = // new SnowflakeConnectionV1(snowhouseProps.getProperty(URL), // snowhouseProps); } catch (SQLException e) { e.printStackTrace(); System.exit(1); } }
Example #4
Source File: BaseIncidentTest.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
@SuppressWarnings("ThrowableNotThrown") void generateIncidentWithSignature(String signature, boolean silenceIncidents) throws SQLException { Connection connection = getSnowflakeAdminConnection(); if (silenceIncidents) { connection.createStatement().execute("alter session set SUPPRESS_INCIDENT_DUMPS=true"); } SFSession session = connection.unwrap(SnowflakeConnectionV1.class).getSfSession(); IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.NON_FATAL_ERROR, signature), null, null); connection.close(); }
Example #5
Source File: IncidentTests.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
/** * Tests for triggering a client incident on GS */ @Test public void simpleFlushTest() throws SQLException { String jobId = "ji"; String requestId = "ri"; String errorMessage = RandomStringUtils.randomAlphabetic(5); SFException exc = new SFException(ErrorCode.INTERNAL_ERROR, errorMessage); String expected_signature = errorMessage + ". at net.snowflake.client.core" + ".IncidentTests.simpleFlushTest(IncidentTests.java:"; Connection connection = getConnection(); Incident incident = new Incident( connection.unwrap(SnowflakeConnectionV1.class).getSfSession(), exc, jobId, requestId ); incident.trigger(); verifyIncidentRegisteredInGS(expected_signature, 1); connection.close(); }
Example #6
Source File: TelemetryClient.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
/** * Initialize the telemetry connector * * @param conn connection with the session to use for the connector * @param flushSize maximum size of telemetry batch before flush * @return a telemetry connector */ public static Telemetry createTelemetry(Connection conn, int flushSize) { try { return createTelemetry(conn.unwrap(SnowflakeConnectionV1.class).getSfSession(), flushSize); } catch (SQLException ex) { logger.debug("input connection is not a SnowflakeConnection"); return null; } }
Example #7
Source File: TestDataConfigBuilder.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
private ResultListener initLoader( Map<LoaderProperty, Object> prop) throws Exception { ResultListener _resultListener = new ResultListener(); // Set up Test parameters streamLoader = (StreamLoader) LoaderFactory.createLoader( prop, putConnection, testConnection); streamLoader.setProperty(LoaderProperty.startTransaction, startTransaction); streamLoader.setProperty(LoaderProperty.truncateTable, truncateTable); streamLoader.setProperty(LoaderProperty.preserveStageFile, preserveStageFile); streamLoader.setProperty(LoaderProperty.useLocalTimezone, useLocalTimezone); streamLoader.setProperty(LoaderProperty.mapTimeToTimestamp, mapTimeToTimestamp); streamLoader.setProperty(LoaderProperty.copyEmptyFieldAsEmpty, copyEmptyFieldAsEmpty); // file bucket size streamLoader.setProperty(LoaderProperty.csvFileBucketSize, Long.toString(csvFileBucketSize)); // file batch streamLoader.setProperty(LoaderProperty.csvFileSize, Long.toString(csvFileSize)); streamLoader.setProperty(LoaderProperty.compressFileByPut, compressFileByPut); streamLoader.setProperty(LoaderProperty.compressDataBeforePut, compressDataBeforePut); streamLoader.setProperty(LoaderProperty.compressLevel, compressLevel); // ON_ERROR option streamLoader.setProperty(LoaderProperty.onError, onError); streamLoader.setListener(_resultListener); // causes upload to fail streamLoader.setTestMode(testMode); // Wait for 5 seconds on first put to buffer everything up. putConnection.unwrap(SnowflakeConnectionV1.class).setInjectedDelay(5000); return _resultListener; }
Example #8
Source File: IncidentTests.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
/** * See if dump file is created by client */ @Test public void testDumpFileCreated() throws Throwable { String errorMessage = "testDumpFile" + RandomStringUtils.randomAlphabetic(5); SFException exc = new SFException(ErrorCode.INTERNAL_ERROR, errorMessage); Connection connection = getConnection(); Incident incident = new Incident(connection.unwrap(SnowflakeConnectionV1.class).getSfSession(), exc, "ji", "ri"); incident.trigger(); String dumpFile = findDmpFile(incident.signature); File file = new File(dumpFile); Assert.assertTrue(file.isFile()); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.contains(incident.signature)) { scanner.close(); cleanUpDmpFile(dumpFile); return; } } Assert.fail("must find the signature"); }
Example #9
Source File: IncidentTests.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
/** * */ @Test public void fullTriggerIncident() throws SQLException { SFException exc = new SFException( ErrorCode.IO_ERROR, "Mark Screwed something up again" + RandomStringUtils.randomAlphabetic(3)); Connection connection = getConnection(); SFSession session = connection.unwrap(SnowflakeConnectionV1.class).getSfSession(); Incident incident = new Incident(session, exc, null, null); String signature = incident.signature; try { // This is how incidents should be raised from now on throw (SFException) IncidentUtil.generateIncidentV2WithException( session, exc, null, null); } catch (SFException ex) { verifyIncidentRegisteredInGS(signature, 1); } finally { connection.close(); } }
Example #10
Source File: LoaderIT.java From components with Apache License 2.0 | 5 votes |
private ResultListener initLoader( Map<LoaderProperty, Object> prop) throws Exception { ResultListener _resultListener = new ResultListener(); // Delete staging area underTest = (StreamLoader) LoaderFactory.createLoader( prop, putConnection, testConnection); underTest.setProperty(LoaderProperty.startTransaction, true); underTest.setProperty(LoaderProperty.truncateTable, true); underTest.setProperty(LoaderProperty.executeBefore, "CREATE TABLE DUMMY_TABLE(i int)"); underTest.setProperty(LoaderProperty.executeAfter, "DROP TABLE DUMMY_TABLE"); underTest.start(); underTest.finish(); // Set up Test parameters underTest = (StreamLoader) LoaderFactory.createLoader( prop, putConnection, testConnection); underTest.setListener(_resultListener); // Wait for 5 seconds on first put to buffer everything up. ((SnowflakeConnectionV1) putConnection).setInjectedDelay(5000); return _resultListener; }