repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.upload
public void upload(Map<String, ParameterBindingDTO> bindValues) throws BindException { if (!closed) { serializeBinds(bindValues); putBinds(); } }
java
public void upload(Map<String, ParameterBindingDTO> bindValues) throws BindException { if (!closed) { serializeBinds(bindValues); putBinds(); } }
[ "public", "void", "upload", "(", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "bindValues", ")", "throws", "BindException", "{", "if", "(", "!", "closed", ")", "{", "serializeBinds", "(", "bindValues", ")", ";", "putBinds", "(", ")", ";", "}", ...
Upload the bindValues to stage @param bindValues the bind map to upload @throws BindException if the bind map could not be serialized or upload fails
[ "Upload", "the", "bindValues", "to", "stage" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L196-L203
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.serializeBinds
private void serializeBinds(Map<String, ParameterBindingDTO> bindValues) throws BindException { List<ColumnTypeDataPair> columns = getColumnValues(bindValues); List<String[]> rows = buildRows(columns); writeRowsToCSV(rows); }
java
private void serializeBinds(Map<String, ParameterBindingDTO> bindValues) throws BindException { List<ColumnTypeDataPair> columns = getColumnValues(bindValues); List<String[]> rows = buildRows(columns); writeRowsToCSV(rows); }
[ "private", "void", "serializeBinds", "(", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "bindValues", ")", "throws", "BindException", "{", "List", "<", "ColumnTypeDataPair", ">", "columns", "=", "getColumnValues", "(", "bindValues", ")", ";", "List", "<...
Save the binds to disk @param bindValues the bind map to serialize @throws BindException if bind map improperly formed or writing binds fails
[ "Save", "the", "binds", "to", "disk" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L211-L216
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.getColumnValues
private List<ColumnTypeDataPair> getColumnValues(Map<String, ParameterBindingDTO> bindValues) throws BindException { List<ColumnTypeDataPair> columns = new ArrayList<>(bindValues.size()); for (int i = 1; i <= bindValues.size(); i++) { // bindValues should have n entries with string keys 1 ... n and list values String key = Integer.toString(i); if (!bindValues.containsKey(key)) { throw new BindException( String.format("Bind map with %d columns should contain key \"%d\"", bindValues.size(), i), BindException.Type.SERIALIZATION); } ParameterBindingDTO value = bindValues.get(key); try { String type = value.getType(); List<String> list = (List<String>) value.getValue(); List<String> convertedList = new ArrayList<>(list.size()); if ("TIMESTAMP_LTZ".equals(type) || "TIMESTAMP_NTZ".equals(type)) { for (String e : list) { convertedList.add(synchronizedTimestampFormat(e)); } } else if ("DATE".equals(type)) { for (String e : list) { convertedList.add(synchronizedDateFormat(e)); } } else { convertedList = list; } columns.add(i - 1, new ColumnTypeDataPair(type, convertedList)); } catch (ClassCastException ex) { throw new BindException("Value in binding DTO could not be cast to a list", BindException.Type.SERIALIZATION); } } return columns; }
java
private List<ColumnTypeDataPair> getColumnValues(Map<String, ParameterBindingDTO> bindValues) throws BindException { List<ColumnTypeDataPair> columns = new ArrayList<>(bindValues.size()); for (int i = 1; i <= bindValues.size(); i++) { // bindValues should have n entries with string keys 1 ... n and list values String key = Integer.toString(i); if (!bindValues.containsKey(key)) { throw new BindException( String.format("Bind map with %d columns should contain key \"%d\"", bindValues.size(), i), BindException.Type.SERIALIZATION); } ParameterBindingDTO value = bindValues.get(key); try { String type = value.getType(); List<String> list = (List<String>) value.getValue(); List<String> convertedList = new ArrayList<>(list.size()); if ("TIMESTAMP_LTZ".equals(type) || "TIMESTAMP_NTZ".equals(type)) { for (String e : list) { convertedList.add(synchronizedTimestampFormat(e)); } } else if ("DATE".equals(type)) { for (String e : list) { convertedList.add(synchronizedDateFormat(e)); } } else { convertedList = list; } columns.add(i - 1, new ColumnTypeDataPair(type, convertedList)); } catch (ClassCastException ex) { throw new BindException("Value in binding DTO could not be cast to a list", BindException.Type.SERIALIZATION); } } return columns; }
[ "private", "List", "<", "ColumnTypeDataPair", ">", "getColumnValues", "(", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "bindValues", ")", "throws", "BindException", "{", "List", "<", "ColumnTypeDataPair", ">", "columns", "=", "new", "ArrayList", "<>", ...
Convert bind map to a list of values for each column Perform necessary type casts and invariant checks @param bindValues the bind map to convert @return list of values for each column @throws BindException if bind map is improperly formed
[ "Convert", "bind", "map", "to", "a", "list", "of", "values", "for", "each", "column", "Perform", "necessary", "type", "casts", "and", "invariant", "checks" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L226-L271
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.buildRows
private List<String[]> buildRows(List<ColumnTypeDataPair> columns) throws BindException { List<String[]> rows = new ArrayList<>(); int numColumns = columns.size(); // columns should have binds if (columns.get(0).data.isEmpty()) { throw new BindException("No binds found in first column", BindException.Type.SERIALIZATION); } int numRows = columns.get(0).data.size(); // every column should have the same number of binds for (int i = 0; i < numColumns; i++) { int iNumRows = columns.get(i).data.size(); if (columns.get(i).data.size() != numRows) { throw new BindException( String.format("Column %d has a different number of binds (%d) than column 1 (%d)", i, iNumRows, numRows), BindException.Type.SERIALIZATION); } } for (int rowIdx = 0; rowIdx < numRows; rowIdx++) { String[] row = new String[numColumns]; for (int colIdx = 0; colIdx < numColumns; colIdx++) { row[colIdx] = columns.get(colIdx).data.get(rowIdx); } rows.add(row); } return rows; }
java
private List<String[]> buildRows(List<ColumnTypeDataPair> columns) throws BindException { List<String[]> rows = new ArrayList<>(); int numColumns = columns.size(); // columns should have binds if (columns.get(0).data.isEmpty()) { throw new BindException("No binds found in first column", BindException.Type.SERIALIZATION); } int numRows = columns.get(0).data.size(); // every column should have the same number of binds for (int i = 0; i < numColumns; i++) { int iNumRows = columns.get(i).data.size(); if (columns.get(i).data.size() != numRows) { throw new BindException( String.format("Column %d has a different number of binds (%d) than column 1 (%d)", i, iNumRows, numRows), BindException.Type.SERIALIZATION); } } for (int rowIdx = 0; rowIdx < numRows; rowIdx++) { String[] row = new String[numColumns]; for (int colIdx = 0; colIdx < numColumns; colIdx++) { row[colIdx] = columns.get(colIdx).data.get(rowIdx); } rows.add(row); } return rows; }
[ "private", "List", "<", "String", "[", "]", ">", "buildRows", "(", "List", "<", "ColumnTypeDataPair", ">", "columns", ")", "throws", "BindException", "{", "List", "<", "String", "[", "]", ">", "rows", "=", "new", "ArrayList", "<>", "(", ")", ";", "int"...
Transpose a list of columns and their values to a list of rows @param columns the list of columns to transpose @return list of rows @throws BindException if columns improperly formed
[ "Transpose", "a", "list", "of", "columns", "and", "their", "values", "to", "a", "list", "of", "rows" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L280-L314
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.writeRowsToCSV
private void writeRowsToCSV(List<String[]> rows) throws BindException { int numBytes; int rowNum = 0; int fileCount = 0; while (rowNum < rows.size()) { File file = getFile(++fileCount); try (OutputStream out = openFile(file)) { // until we reach the last row or the file is too big, write to the file numBytes = 0; while (numBytes < fileSize && rowNum < rows.size()) { byte[] csv = createCSVRecord(rows.get(rowNum)); numBytes += csv.length; out.write(csv); rowNum++; } } catch (IOException ex) { throw new BindException( String.format("Exception encountered while writing to file: %s", ex.getMessage()), BindException.Type.SERIALIZATION); } } }
java
private void writeRowsToCSV(List<String[]> rows) throws BindException { int numBytes; int rowNum = 0; int fileCount = 0; while (rowNum < rows.size()) { File file = getFile(++fileCount); try (OutputStream out = openFile(file)) { // until we reach the last row or the file is too big, write to the file numBytes = 0; while (numBytes < fileSize && rowNum < rows.size()) { byte[] csv = createCSVRecord(rows.get(rowNum)); numBytes += csv.length; out.write(csv); rowNum++; } } catch (IOException ex) { throw new BindException( String.format("Exception encountered while writing to file: %s", ex.getMessage()), BindException.Type.SERIALIZATION); } } }
[ "private", "void", "writeRowsToCSV", "(", "List", "<", "String", "[", "]", ">", "rows", ")", "throws", "BindException", "{", "int", "numBytes", ";", "int", "rowNum", "=", "0", ";", "int", "fileCount", "=", "0", ";", "while", "(", "rowNum", "<", "rows",...
Write the list of rows to compressed CSV files in the temporary directory @param rows the list of rows to write out to a file @throws BindException if exception occurs while writing rows out
[ "Write", "the", "list", "of", "rows", "to", "compressed", "CSV", "files", "in", "the", "temporary", "directory" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L322-L350
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.openFile
private OutputStream openFile(File file) throws BindException { try { return new GZIPOutputStream(new FileOutputStream(file)); } catch (IOException ex) { throw new BindException( String.format("Failed to create output file %s: %s", file.toString(), ex.getMessage()), BindException.Type.SERIALIZATION); } }
java
private OutputStream openFile(File file) throws BindException { try { return new GZIPOutputStream(new FileOutputStream(file)); } catch (IOException ex) { throw new BindException( String.format("Failed to create output file %s: %s", file.toString(), ex.getMessage()), BindException.Type.SERIALIZATION); } }
[ "private", "OutputStream", "openFile", "(", "File", "file", ")", "throws", "BindException", "{", "try", "{", "return", "new", "GZIPOutputStream", "(", "new", "FileOutputStream", "(", "file", ")", ")", ";", "}", "catch", "(", "IOException", "ex", ")", "{", ...
Create a new output stream for the given file @param file the file to write out to @return output stream @throws BindException raises if it fails to create an output file.
[ "Create", "a", "new", "output", "stream", "for", "the", "given", "file" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L370-L381
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.createCSVRecord
private byte[] createCSVRecord(String[] data) { StringBuilder sb = new StringBuilder(1024); for (int i = 0; i < data.length; ++i) { if (i > 0) { sb.append(','); } sb.append(SnowflakeType.escapeForCSV(data[i])); } sb.append('\n'); return sb.toString().getBytes(UTF_8); }
java
private byte[] createCSVRecord(String[] data) { StringBuilder sb = new StringBuilder(1024); for (int i = 0; i < data.length; ++i) { if (i > 0) { sb.append(','); } sb.append(SnowflakeType.escapeForCSV(data[i])); } sb.append('\n'); return sb.toString().getBytes(UTF_8); }
[ "private", "byte", "[", "]", "createCSVRecord", "(", "String", "[", "]", "data", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "1024", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "data", ".", "length", ";", "++",...
Serialize row to a csv Duplicated from StreamLoader class @param data the row to create a csv record from @return serialized csv for row
[ "Serialize", "row", "to", "a", "csv", "Duplicated", "from", "StreamLoader", "class" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L390-L404
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.getPutStmt
private String getPutStmt(String bindDir, String stagePath) { return String.format(PUT_STMT, bindDir, File.separator, stagePath) .replaceAll("\\\\", "\\\\\\\\"); }
java
private String getPutStmt(String bindDir, String stagePath) { return String.format(PUT_STMT, bindDir, File.separator, stagePath) .replaceAll("\\\\", "\\\\\\\\"); }
[ "private", "String", "getPutStmt", "(", "String", "bindDir", ",", "String", "stagePath", ")", "{", "return", "String", ".", "format", "(", "PUT_STMT", ",", "bindDir", ",", "File", ".", "separator", ",", "stagePath", ")", ".", "replaceAll", "(", "\"\\\\\\\\\"...
Build PUT statement string. Handle filesystem differences and escaping backslashes. @param bindDir the local directory which contains files with binds @param stagePath the stage path to upload to @return put statement for files in bindDir to stagePath
[ "Build", "PUT", "statement", "string", ".", "Handle", "filesystem", "differences", "and", "escaping", "backslashes", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L413-L417
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.putBinds
private void putBinds() throws BindException { createStageIfNeeded(); String putStatement = getPutStmt(bindDir.toString(), stagePath); for (int i = 0; i < PUT_RETRY_COUNT; i++) { try { SFStatement statement = new SFStatement(session); SFBaseResultSet putResult = statement.execute(putStatement, null, null); putResult.next(); // metadata is 0-based, result set is 1-based int column = putResult.getMetaData().getColumnIndex( SnowflakeFileTransferAgent.UploadColumns.status.name()) + 1; String status = putResult.getString(column); if (SnowflakeFileTransferAgent.ResultStatus.UPLOADED.name().equals(status)) { return; // success! } logger.debug("PUT statement failed. The response had status %s.", status); } catch (SFException | SQLException ex) { logger.debug("Exception encountered during PUT operation. ", ex); } } // if we haven't returned (on success), throw exception throw new BindException("Failed to PUT files to stage.", BindException.Type.UPLOAD); }
java
private void putBinds() throws BindException { createStageIfNeeded(); String putStatement = getPutStmt(bindDir.toString(), stagePath); for (int i = 0; i < PUT_RETRY_COUNT; i++) { try { SFStatement statement = new SFStatement(session); SFBaseResultSet putResult = statement.execute(putStatement, null, null); putResult.next(); // metadata is 0-based, result set is 1-based int column = putResult.getMetaData().getColumnIndex( SnowflakeFileTransferAgent.UploadColumns.status.name()) + 1; String status = putResult.getString(column); if (SnowflakeFileTransferAgent.ResultStatus.UPLOADED.name().equals(status)) { return; // success! } logger.debug("PUT statement failed. The response had status %s.", status); } catch (SFException | SQLException ex) { logger.debug("Exception encountered during PUT operation. ", ex); } } // if we haven't returned (on success), throw exception throw new BindException("Failed to PUT files to stage.", BindException.Type.UPLOAD); }
[ "private", "void", "putBinds", "(", ")", "throws", "BindException", "{", "createStageIfNeeded", "(", ")", ";", "String", "putStatement", "=", "getPutStmt", "(", "bindDir", ".", "toString", "(", ")", ",", "stagePath", ")", ";", "for", "(", "int", "i", "=", ...
Upload binds from local file to stage @throws BindException if uploading the binds fails
[ "Upload", "binds", "from", "local", "file", "to", "stage" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L424-L457
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.createStageIfNeeded
private void createStageIfNeeded() throws BindException { if (session.getArrayBindStage() != null) { return; } synchronized (session) { // another thread may have created the session by the time we enter this block if (session.getArrayBindStage() == null) { try { SFStatement statement = new SFStatement(session); statement.execute(CREATE_STAGE_STMT, null, null); session.setArrayBindStage(STAGE_NAME); } catch (SFException | SQLException ex) { // to avoid repeated failures to create stage, disable array bind stage // optimization if we fail to create stage for some reason session.setArrayBindStageThreshold(0); throw new BindException( String.format("Failed to create temporary stage for array binds. %s", ex.getMessage()), BindException.Type.UPLOAD); } } } }
java
private void createStageIfNeeded() throws BindException { if (session.getArrayBindStage() != null) { return; } synchronized (session) { // another thread may have created the session by the time we enter this block if (session.getArrayBindStage() == null) { try { SFStatement statement = new SFStatement(session); statement.execute(CREATE_STAGE_STMT, null, null); session.setArrayBindStage(STAGE_NAME); } catch (SFException | SQLException ex) { // to avoid repeated failures to create stage, disable array bind stage // optimization if we fail to create stage for some reason session.setArrayBindStageThreshold(0); throw new BindException( String.format("Failed to create temporary stage for array binds. %s", ex.getMessage()), BindException.Type.UPLOAD); } } } }
[ "private", "void", "createStageIfNeeded", "(", ")", "throws", "BindException", "{", "if", "(", "session", ".", "getArrayBindStage", "(", ")", "!=", "null", ")", "{", "return", ";", "}", "synchronized", "(", "session", ")", "{", "// another thread may have create...
Check whether the session's temporary stage has been created, and create it if not. @throws BindException if creating the stage fails
[ "Check", "whether", "the", "session", "s", "temporary", "stage", "has", "been", "created", "and", "create", "it", "if", "not", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L465-L492
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.arrayBindValueCount
public static int arrayBindValueCount(Map<String, ParameterBindingDTO> bindValues) { if (!isArrayBind(bindValues)) { return 0; } else { ParameterBindingDTO bindSample = bindValues.values().iterator().next(); List<String> bindSampleValues = (List<String>) bindSample.getValue(); return bindValues.size() * bindSampleValues.size(); } }
java
public static int arrayBindValueCount(Map<String, ParameterBindingDTO> bindValues) { if (!isArrayBind(bindValues)) { return 0; } else { ParameterBindingDTO bindSample = bindValues.values().iterator().next(); List<String> bindSampleValues = (List<String>) bindSample.getValue(); return bindValues.size() * bindSampleValues.size(); } }
[ "public", "static", "int", "arrayBindValueCount", "(", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "bindValues", ")", "{", "if", "(", "!", "isArrayBind", "(", "bindValues", ")", ")", "{", "return", "0", ";", "}", "else", "{", "ParameterBindingDTO"...
Compute the number of array bind values in the given bind map @param bindValues the bind map @return 0 if bindValues is null, has no binds, or is not an array bind n otherwise, where n is the number of binds in the array bind
[ "Compute", "the", "number", "of", "array", "bind", "values", "in", "the", "given", "bind", "map" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L568-L580
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/bind/BindUploader.java
BindUploader.isArrayBind
public static boolean isArrayBind(Map<String, ParameterBindingDTO> bindValues) { if (bindValues == null || bindValues.size() == 0) { return false; } ParameterBindingDTO bindSample = bindValues.values().iterator().next(); return bindSample.getValue() instanceof List; }
java
public static boolean isArrayBind(Map<String, ParameterBindingDTO> bindValues) { if (bindValues == null || bindValues.size() == 0) { return false; } ParameterBindingDTO bindSample = bindValues.values().iterator().next(); return bindSample.getValue() instanceof List; }
[ "public", "static", "boolean", "isArrayBind", "(", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "bindValues", ")", "{", "if", "(", "bindValues", "==", "null", "||", "bindValues", ".", "size", "(", ")", "==", "0", ")", "{", "return", "false", ";...
Return whether the bind map uses array binds @param bindValues the bind map @return whether the bind map uses array binds
[ "Return", "whether", "the", "bind", "map", "uses", "array", "binds" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/bind/BindUploader.java#L588-L596
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/StorageObjectSummary.java
StorageObjectSummary.createFromS3ObjectSummary
public static StorageObjectSummary createFromS3ObjectSummary(S3ObjectSummary objSummary) { return new StorageObjectSummary( objSummary.getBucketName(), objSummary.getKey(), // S3 ETag is not always MD5, but since this code path is only // used in skip duplicate files in PUT command, It's not // critical to guarantee that it's MD5 objSummary.getETag(), objSummary.getSize() ); }
java
public static StorageObjectSummary createFromS3ObjectSummary(S3ObjectSummary objSummary) { return new StorageObjectSummary( objSummary.getBucketName(), objSummary.getKey(), // S3 ETag is not always MD5, but since this code path is only // used in skip duplicate files in PUT command, It's not // critical to guarantee that it's MD5 objSummary.getETag(), objSummary.getSize() ); }
[ "public", "static", "StorageObjectSummary", "createFromS3ObjectSummary", "(", "S3ObjectSummary", "objSummary", ")", "{", "return", "new", "StorageObjectSummary", "(", "objSummary", ".", "getBucketName", "(", ")", ",", "objSummary", ".", "getKey", "(", ")", ",", "// ...
Contructs a StorageObjectSummary object from the S3 equivalent S3ObjectSummary @param objSummary the AWS S3 ObjectSummary object to copy from @return the ObjectSummary object created
[ "Contructs", "a", "StorageObjectSummary", "object", "from", "the", "S3", "equivalent", "S3ObjectSummary" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/StorageObjectSummary.java#L47-L59
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/StorageObjectSummary.java
StorageObjectSummary.createFromAzureListBlobItem
public static StorageObjectSummary createFromAzureListBlobItem(ListBlobItem listBlobItem) throws StorageProviderException { String location, key, md5; long size; // Retrieve the BLOB properties that we need for the Summary // Azure Storage stores metadata inside each BLOB, therefore the listBlobItem // will point us to the underlying BLOB and will get the properties from it // During the process the Storage Client could fail, hence we need to wrap the // get calls in try/catch and handle possible exceptions try { location = listBlobItem.getContainer().getName(); CloudBlob cloudBlob = (CloudBlob) listBlobItem; key = cloudBlob.getName(); BlobProperties blobProperties = cloudBlob.getProperties(); // the content md5 property is not always the actual md5 of the file. But for here, it's only // used for skipping file on PUT command, hense is ok. md5 = convertBase64ToHex(blobProperties.getContentMD5()); size = blobProperties.getLength(); } catch (URISyntaxException | StorageException ex) { // This should only happen if somehow we got here with and invalid URI (it should never happen) // ...or there is a Storage service error. Unlike S3, Azure fetches metadata from the BLOB itself, // and its a lazy operation throw new StorageProviderException(ex); } return new StorageObjectSummary(location, key, md5, size); }
java
public static StorageObjectSummary createFromAzureListBlobItem(ListBlobItem listBlobItem) throws StorageProviderException { String location, key, md5; long size; // Retrieve the BLOB properties that we need for the Summary // Azure Storage stores metadata inside each BLOB, therefore the listBlobItem // will point us to the underlying BLOB and will get the properties from it // During the process the Storage Client could fail, hence we need to wrap the // get calls in try/catch and handle possible exceptions try { location = listBlobItem.getContainer().getName(); CloudBlob cloudBlob = (CloudBlob) listBlobItem; key = cloudBlob.getName(); BlobProperties blobProperties = cloudBlob.getProperties(); // the content md5 property is not always the actual md5 of the file. But for here, it's only // used for skipping file on PUT command, hense is ok. md5 = convertBase64ToHex(blobProperties.getContentMD5()); size = blobProperties.getLength(); } catch (URISyntaxException | StorageException ex) { // This should only happen if somehow we got here with and invalid URI (it should never happen) // ...or there is a Storage service error. Unlike S3, Azure fetches metadata from the BLOB itself, // and its a lazy operation throw new StorageProviderException(ex); } return new StorageObjectSummary(location, key, md5, size); }
[ "public", "static", "StorageObjectSummary", "createFromAzureListBlobItem", "(", "ListBlobItem", "listBlobItem", ")", "throws", "StorageProviderException", "{", "String", "location", ",", "key", ",", "md5", ";", "long", "size", ";", "// Retrieve the BLOB properties that we n...
Contructs a StorageObjectSummary object from Azure BLOB properties Using factory methods to create these objects since Azure can throw, while retrieving the BLOB properties @param listBlobItem an Azure ListBlobItem object @return the ObjectSummary object created
[ "Contructs", "a", "StorageObjectSummary", "object", "from", "Azure", "BLOB", "properties", "Using", "factory", "methods", "to", "create", "these", "objects", "since", "Azure", "can", "throw", "while", "retrieving", "the", "BLOB", "properties" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/StorageObjectSummary.java#L69-L102
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.isSnowflakeAuthenticator
private boolean isSnowflakeAuthenticator() { String authenticator = (String) connectionPropertiesMap.get( SFSessionProperty.AUTHENTICATOR); PrivateKey privateKey = (PrivateKey) connectionPropertiesMap.get( SFSessionProperty.PRIVATE_KEY); return (authenticator == null && privateKey == null) || ClientAuthnDTO.AuthenticatorType.SNOWFLAKE.name() .equalsIgnoreCase(authenticator); }
java
private boolean isSnowflakeAuthenticator() { String authenticator = (String) connectionPropertiesMap.get( SFSessionProperty.AUTHENTICATOR); PrivateKey privateKey = (PrivateKey) connectionPropertiesMap.get( SFSessionProperty.PRIVATE_KEY); return (authenticator == null && privateKey == null) || ClientAuthnDTO.AuthenticatorType.SNOWFLAKE.name() .equalsIgnoreCase(authenticator); }
[ "private", "boolean", "isSnowflakeAuthenticator", "(", ")", "{", "String", "authenticator", "=", "(", "String", ")", "connectionPropertiesMap", ".", "get", "(", "SFSessionProperty", ".", "AUTHENTICATOR", ")", ";", "PrivateKey", "privateKey", "=", "(", "PrivateKey", ...
If authenticator is null and private key is specified, jdbc will assume key pair authentication @return true if authenticator type is SNOWFLAKE (meaning password)
[ "If", "authenticator", "is", "null", "and", "private", "key", "is", "specified", "jdbc", "will", "assume", "key", "pair", "authentication" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L333-L344
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.isExternalbrowserAuthenticator
boolean isExternalbrowserAuthenticator() { String authenticator = (String) connectionPropertiesMap.get( SFSessionProperty.AUTHENTICATOR); return ClientAuthnDTO.AuthenticatorType.EXTERNALBROWSER.name() .equalsIgnoreCase(authenticator); }
java
boolean isExternalbrowserAuthenticator() { String authenticator = (String) connectionPropertiesMap.get( SFSessionProperty.AUTHENTICATOR); return ClientAuthnDTO.AuthenticatorType.EXTERNALBROWSER.name() .equalsIgnoreCase(authenticator); }
[ "boolean", "isExternalbrowserAuthenticator", "(", ")", "{", "String", "authenticator", "=", "(", "String", ")", "connectionPropertiesMap", ".", "get", "(", "SFSessionProperty", ".", "AUTHENTICATOR", ")", ";", "return", "ClientAuthnDTO", ".", "AuthenticatorType", ".", ...
Returns true If authenticator is EXTERNALBROWSER. @return true if authenticator type is EXTERNALBROWSER
[ "Returns", "true", "If", "authenticator", "is", "EXTERNALBROWSER", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L351-L357
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.renewSession
synchronized void renewSession(String prevSessionToken) throws SFException, SnowflakeSQLException { if (sessionToken != null && !sessionToken.equals(prevSessionToken)) { logger.debug("not renew session because session token has not been updated."); return; } SessionUtil.LoginInput loginInput = new SessionUtil.LoginInput(); loginInput.setServerUrl( (String) connectionPropertiesMap.get(SFSessionProperty.SERVER_URL)) .setSessionToken(sessionToken) .setMasterToken(masterToken) .setIdToken(idToken) .setLoginTimeout(loginTimeout) .setDatabaseName(this.getDatabase()) .setSchemaName(this.getSchema()) .setRole(this.getRole()) .setWarehouse(this.getWarehouse()); SessionUtil.LoginOutput loginOutput = SessionUtil.renewSession(loginInput); if (loginOutput.isUpdatedByTokenRequestIssue()) { setCurrentObjects(loginInput, loginOutput); } sessionToken = loginOutput.getSessionToken(); masterToken = loginOutput.getMasterToken(); }
java
synchronized void renewSession(String prevSessionToken) throws SFException, SnowflakeSQLException { if (sessionToken != null && !sessionToken.equals(prevSessionToken)) { logger.debug("not renew session because session token has not been updated."); return; } SessionUtil.LoginInput loginInput = new SessionUtil.LoginInput(); loginInput.setServerUrl( (String) connectionPropertiesMap.get(SFSessionProperty.SERVER_URL)) .setSessionToken(sessionToken) .setMasterToken(masterToken) .setIdToken(idToken) .setLoginTimeout(loginTimeout) .setDatabaseName(this.getDatabase()) .setSchemaName(this.getSchema()) .setRole(this.getRole()) .setWarehouse(this.getWarehouse()); SessionUtil.LoginOutput loginOutput = SessionUtil.renewSession(loginInput); if (loginOutput.isUpdatedByTokenRequestIssue()) { setCurrentObjects(loginInput, loginOutput); } sessionToken = loginOutput.getSessionToken(); masterToken = loginOutput.getMasterToken(); }
[ "synchronized", "void", "renewSession", "(", "String", "prevSessionToken", ")", "throws", "SFException", ",", "SnowflakeSQLException", "{", "if", "(", "sessionToken", "!=", "null", "&&", "!", "sessionToken", ".", "equals", "(", "prevSessionToken", ")", ")", "{", ...
A helper function to call global service and renew session. @param prevSessionToken the session token that has expired @throws SnowflakeSQLException if failed to renew the session @throws SFException if failed to renew the session
[ "A", "helper", "function", "to", "call", "global", "service", "and", "renew", "session", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L608-L638
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.startHeartbeatForThisSession
protected void startHeartbeatForThisSession() { if (enableHeartbeat && !Strings.isNullOrEmpty(masterToken)) { logger.debug("start heartbeat, master token validity: " + masterTokenValidityInSeconds); HeartbeatBackground.getInstance().addSession(this, masterTokenValidityInSeconds, this.heartbeatFrequency); } else { logger.debug("heartbeat not enabled for the session"); } }
java
protected void startHeartbeatForThisSession() { if (enableHeartbeat && !Strings.isNullOrEmpty(masterToken)) { logger.debug("start heartbeat, master token validity: " + masterTokenValidityInSeconds); HeartbeatBackground.getInstance().addSession(this, masterTokenValidityInSeconds, this.heartbeatFrequency); } else { logger.debug("heartbeat not enabled for the session"); } }
[ "protected", "void", "startHeartbeatForThisSession", "(", ")", "{", "if", "(", "enableHeartbeat", "&&", "!", "Strings", ".", "isNullOrEmpty", "(", "masterToken", ")", ")", "{", "logger", ".", "debug", "(", "\"start heartbeat, master token validity: \"", "+", "master...
Start heartbeat for this session
[ "Start", "heartbeat", "for", "this", "session" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L683-L697
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.stopHeartbeatForThisSession
protected void stopHeartbeatForThisSession() { if (enableHeartbeat && !Strings.isNullOrEmpty(masterToken)) { logger.debug("stop heartbeat"); HeartbeatBackground.getInstance().removeSession(this); } else { logger.debug("heartbeat not enabled for the session"); } }
java
protected void stopHeartbeatForThisSession() { if (enableHeartbeat && !Strings.isNullOrEmpty(masterToken)) { logger.debug("stop heartbeat"); HeartbeatBackground.getInstance().removeSession(this); } else { logger.debug("heartbeat not enabled for the session"); } }
[ "protected", "void", "stopHeartbeatForThisSession", "(", ")", "{", "if", "(", "enableHeartbeat", "&&", "!", "Strings", ".", "isNullOrEmpty", "(", "masterToken", ")", ")", "{", "logger", ".", "debug", "(", "\"stop heartbeat\"", ")", ";", "HeartbeatBackground", "....
Stop heartbeat for this session
[ "Stop", "heartbeat", "for", "this", "session" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L702-L714
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.heartbeat
protected void heartbeat() throws SFException, SQLException { logger.debug(" public void heartbeat()"); if (isClosed) { return; } HttpPost postRequest = null; String requestId = UUID.randomUUID().toString(); boolean retry = false; // the loop for retrying if it runs into session expiration do { try { URIBuilder uriBuilder; uriBuilder = new URIBuilder( (String) connectionPropertiesMap.get(SFSessionProperty.SERVER_URL)); uriBuilder.addParameter(SFSession.SF_QUERY_REQUEST_ID, requestId); uriBuilder.setPath(SF_PATH_SESSION_HEARTBEAT); postRequest = new HttpPost(uriBuilder.build()); // remember the session token in case it expires we need to renew // the session only when no other thread has renewed it String prevSessionToken = sessionToken; postRequest.setHeader(SF_HEADER_AUTHORIZATION, SF_HEADER_SNOWFLAKE_AUTHTYPE + " " + SF_HEADER_TOKEN_TAG + "=\"" + prevSessionToken + "\""); logger.debug("Executing heartbeat request: {}", postRequest.toString()); // the following will retry transient network issues String theResponse = HttpUtil.executeRequest(postRequest, SF_HEARTBEAT_TIMEOUT, 0, null); JsonNode rootNode; logger.debug("connection heartbeat response: {}", theResponse); rootNode = mapper.readTree(theResponse); // check the response to see if it is session expiration response if (rootNode != null && (Constants.SESSION_EXPIRED_GS_CODE == rootNode.path("code").asInt())) { logger.debug("renew session and retry"); this.renewSession(prevSessionToken); retry = true; continue; } SnowflakeUtil.checkErrorAndThrowException(rootNode); // success retry = false; } catch (Throwable ex) { // for snowflake exception, just rethrow it if (ex instanceof SnowflakeSQLException) { throw (SnowflakeSQLException) ex; } logger.error("unexpected exception", ex); throw (SFException) IncidentUtil.generateIncidentV2WithException( this, new SFException(ErrorCode.INTERNAL_ERROR, IncidentUtil.oneLiner("unexpected exception", ex)), null, requestId); } } while (retry); }
java
protected void heartbeat() throws SFException, SQLException { logger.debug(" public void heartbeat()"); if (isClosed) { return; } HttpPost postRequest = null; String requestId = UUID.randomUUID().toString(); boolean retry = false; // the loop for retrying if it runs into session expiration do { try { URIBuilder uriBuilder; uriBuilder = new URIBuilder( (String) connectionPropertiesMap.get(SFSessionProperty.SERVER_URL)); uriBuilder.addParameter(SFSession.SF_QUERY_REQUEST_ID, requestId); uriBuilder.setPath(SF_PATH_SESSION_HEARTBEAT); postRequest = new HttpPost(uriBuilder.build()); // remember the session token in case it expires we need to renew // the session only when no other thread has renewed it String prevSessionToken = sessionToken; postRequest.setHeader(SF_HEADER_AUTHORIZATION, SF_HEADER_SNOWFLAKE_AUTHTYPE + " " + SF_HEADER_TOKEN_TAG + "=\"" + prevSessionToken + "\""); logger.debug("Executing heartbeat request: {}", postRequest.toString()); // the following will retry transient network issues String theResponse = HttpUtil.executeRequest(postRequest, SF_HEARTBEAT_TIMEOUT, 0, null); JsonNode rootNode; logger.debug("connection heartbeat response: {}", theResponse); rootNode = mapper.readTree(theResponse); // check the response to see if it is session expiration response if (rootNode != null && (Constants.SESSION_EXPIRED_GS_CODE == rootNode.path("code").asInt())) { logger.debug("renew session and retry"); this.renewSession(prevSessionToken); retry = true; continue; } SnowflakeUtil.checkErrorAndThrowException(rootNode); // success retry = false; } catch (Throwable ex) { // for snowflake exception, just rethrow it if (ex instanceof SnowflakeSQLException) { throw (SnowflakeSQLException) ex; } logger.error("unexpected exception", ex); throw (SFException) IncidentUtil.generateIncidentV2WithException( this, new SFException(ErrorCode.INTERNAL_ERROR, IncidentUtil.oneLiner("unexpected exception", ex)), null, requestId); } } while (retry); }
[ "protected", "void", "heartbeat", "(", ")", "throws", "SFException", ",", "SQLException", "{", "logger", ".", "debug", "(", "\" public void heartbeat()\"", ")", ";", "if", "(", "isClosed", ")", "{", "return", ";", "}", "HttpPost", "postRequest", "=", "null", ...
Send heartbeat for the session @throws SFException exception raised from Snowflake @throws SQLException exception raised from SQL generic layers
[ "Send", "heartbeat", "for", "the", "session" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L722-L811
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSession.java
SFSession.setCurrentObjects
void setCurrentObjects( SessionUtil.LoginInput loginInput, SessionUtil.LoginOutput loginOutput) { this.sessionToken = loginOutput.sessionToken; // used to run the commands. runInternalCommand( "USE ROLE IDENTIFIER(?)", loginInput.getRole()); runInternalCommand( "USE WAREHOUSE IDENTIFIER(?)", loginInput.getWarehouse()); runInternalCommand( "USE DATABASE IDENTIFIER(?)", loginInput.getDatabaseName()); runInternalCommand( "USE SCHEMA IDENTIFIER(?)", loginInput.getSchemaName()); // This ensures the session returns the current objects and refresh // the local cache. SFBaseResultSet result = runInternalCommand("SELECT ?", "1"); // refresh the current objects loginOutput.setSessionDatabase(this.database); loginOutput.setSessionSchema(this.schema); loginOutput.setSessionWarehouse(this.warehouse); loginOutput.setSessionRole(this.role); loginOutput.setIdToken(loginInput.getIdToken()); // no common parameter is updated. if (result != null) { loginOutput.setCommonParams(result.parameters); } }
java
void setCurrentObjects( SessionUtil.LoginInput loginInput, SessionUtil.LoginOutput loginOutput) { this.sessionToken = loginOutput.sessionToken; // used to run the commands. runInternalCommand( "USE ROLE IDENTIFIER(?)", loginInput.getRole()); runInternalCommand( "USE WAREHOUSE IDENTIFIER(?)", loginInput.getWarehouse()); runInternalCommand( "USE DATABASE IDENTIFIER(?)", loginInput.getDatabaseName()); runInternalCommand( "USE SCHEMA IDENTIFIER(?)", loginInput.getSchemaName()); // This ensures the session returns the current objects and refresh // the local cache. SFBaseResultSet result = runInternalCommand("SELECT ?", "1"); // refresh the current objects loginOutput.setSessionDatabase(this.database); loginOutput.setSessionSchema(this.schema); loginOutput.setSessionWarehouse(this.warehouse); loginOutput.setSessionRole(this.role); loginOutput.setIdToken(loginInput.getIdToken()); // no common parameter is updated. if (result != null) { loginOutput.setCommonParams(result.parameters); } }
[ "void", "setCurrentObjects", "(", "SessionUtil", ".", "LoginInput", "loginInput", ",", "SessionUtil", ".", "LoginOutput", "loginOutput", ")", "{", "this", ".", "sessionToken", "=", "loginOutput", ".", "sessionToken", ";", "// used to run the commands.", "runInternalComm...
Sets the current objects if the session is not up to date. It can happen if the session is created by the id token, which doesn't carry the current objects. @param loginInput @param loginOutput
[ "Sets", "the", "current", "objects", "if", "the", "session", "is", "not", "up", "to", "date", ".", "It", "can", "happen", "if", "the", "session", "is", "created", "by", "the", "id", "token", "which", "doesn", "t", "carry", "the", "current", "objects", ...
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSession.java#L1199-L1227
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java
SnowflakeConnectionV1.executeImmediate
private void executeImmediate(String stmtText) throws SQLException { // execute the statement and auto-close it as well try (final Statement statement = this.createStatement()) { statement.execute(stmtText); } }
java
private void executeImmediate(String stmtText) throws SQLException { // execute the statement and auto-close it as well try (final Statement statement = this.createStatement()) { statement.execute(stmtText); } }
[ "private", "void", "executeImmediate", "(", "String", "stmtText", ")", "throws", "SQLException", "{", "// execute the statement and auto-close it as well", "try", "(", "final", "Statement", "statement", "=", "this", ".", "createStatement", "(", ")", ")", "{", "stateme...
Execute a statement where the result isn't needed, and the statement is closed before this method returns @param stmtText text of the statement @throws SQLException exception thrown it the statement fails to execute
[ "Execute", "a", "statement", "where", "the", "result", "isn", "t", "needed", "and", "the", "statement", "is", "closed", "before", "this", "method", "returns" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java#L275-L282
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java
SnowflakeConnectionV1.createStatement
@Override public Statement createStatement() throws SQLException { raiseSQLExceptionIfConnectionIsClosed(); Statement stmt = createStatement( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); openStatements.add(stmt); return stmt; }
java
@Override public Statement createStatement() throws SQLException { raiseSQLExceptionIfConnectionIsClosed(); Statement stmt = createStatement( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); openStatements.add(stmt); return stmt; }
[ "@", "Override", "public", "Statement", "createStatement", "(", ")", "throws", "SQLException", "{", "raiseSQLExceptionIfConnectionIsClosed", "(", ")", ";", "Statement", "stmt", "=", "createStatement", "(", "ResultSet", ".", "TYPE_FORWARD_ONLY", ",", "ResultSet", ".", ...
Create a statement @return statement statement object @throws SQLException if failed to create a snowflake statement
[ "Create", "a", "statement" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java#L290-L299
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java
SnowflakeConnectionV1.setTransactionIsolation
@Override public void setTransactionIsolation(int level) throws SQLException { logger.debug( "void setTransactionIsolation(int level), level = {}", level); raiseSQLExceptionIfConnectionIsClosed(); if (level == Connection.TRANSACTION_NONE || level == Connection.TRANSACTION_READ_COMMITTED) { this.transactionIsolation = level; } else { throw new SQLFeatureNotSupportedException( "Transaction Isolation " + level + " not supported.", FEATURE_UNSUPPORTED.getSqlState(), FEATURE_UNSUPPORTED.getMessageCode()); } }
java
@Override public void setTransactionIsolation(int level) throws SQLException { logger.debug( "void setTransactionIsolation(int level), level = {}", level); raiseSQLExceptionIfConnectionIsClosed(); if (level == Connection.TRANSACTION_NONE || level == Connection.TRANSACTION_READ_COMMITTED) { this.transactionIsolation = level; } else { throw new SQLFeatureNotSupportedException( "Transaction Isolation " + level + " not supported.", FEATURE_UNSUPPORTED.getSqlState(), FEATURE_UNSUPPORTED.getMessageCode()); } }
[ "@", "Override", "public", "void", "setTransactionIsolation", "(", "int", "level", ")", "throws", "SQLException", "{", "logger", ".", "debug", "(", "\"void setTransactionIsolation(int level), level = {}\"", ",", "level", ")", ";", "raiseSQLExceptionIfConnectionIsClosed", ...
Sets the transaction isolation level. @param level transaction level: TRANSACTION_NONE or TRANSACTION_READ_COMMITTED @throws SQLException if any SQL error occurs
[ "Sets", "the", "transaction", "isolation", "level", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java#L501-L519
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java
SnowflakeConnectionV1.downloadStream
public InputStream downloadStream(String stageName, String sourceFileName, boolean decompress) throws SQLException { logger.debug("download data to stream: stageName={}" + ", sourceFileName={}", stageName, sourceFileName); if (Strings.isNullOrEmpty(stageName)) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "stage name is null or empty"); } if (Strings.isNullOrEmpty(sourceFileName)) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "source file name is null or empty"); } SnowflakeStatementV1 stmt = new SnowflakeStatementV1( this, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT); StringBuilder getCommand = new StringBuilder(); getCommand.append("get "); if (!stageName.startsWith("@")) { getCommand.append("@"); } getCommand.append(stageName); getCommand.append("/"); if (sourceFileName.startsWith("/")) { sourceFileName = sourceFileName.substring(1); } getCommand.append(sourceFileName); //this is a fake path, used to form Get query and retrieve stage info, //no file will be downloaded to this location getCommand.append(" file:///tmp/ /*jdbc download stream*/"); SnowflakeFileTransferAgent transferAgent = new SnowflakeFileTransferAgent(getCommand.toString(), sfSession, stmt.getSfStatement()); InputStream stream = transferAgent.downloadStream(sourceFileName); if (decompress) { try { return new GZIPInputStream(stream); } catch (IOException ex) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex.getMessage()); } } else { return stream; } }
java
public InputStream downloadStream(String stageName, String sourceFileName, boolean decompress) throws SQLException { logger.debug("download data to stream: stageName={}" + ", sourceFileName={}", stageName, sourceFileName); if (Strings.isNullOrEmpty(stageName)) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "stage name is null or empty"); } if (Strings.isNullOrEmpty(sourceFileName)) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "source file name is null or empty"); } SnowflakeStatementV1 stmt = new SnowflakeStatementV1( this, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT); StringBuilder getCommand = new StringBuilder(); getCommand.append("get "); if (!stageName.startsWith("@")) { getCommand.append("@"); } getCommand.append(stageName); getCommand.append("/"); if (sourceFileName.startsWith("/")) { sourceFileName = sourceFileName.substring(1); } getCommand.append(sourceFileName); //this is a fake path, used to form Get query and retrieve stage info, //no file will be downloaded to this location getCommand.append(" file:///tmp/ /*jdbc download stream*/"); SnowflakeFileTransferAgent transferAgent = new SnowflakeFileTransferAgent(getCommand.toString(), sfSession, stmt.getSfStatement()); InputStream stream = transferAgent.downloadStream(sourceFileName); if (decompress) { try { return new GZIPInputStream(stream); } catch (IOException ex) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex.getMessage()); } } else { return stream; } }
[ "public", "InputStream", "downloadStream", "(", "String", "stageName", ",", "String", "sourceFileName", ",", "boolean", "decompress", ")", "throws", "SQLException", "{", "logger", ".", "debug", "(", "\"download data to stream: stageName={}\"", "+", "\", sourceFileName={}\...
Download file from the given stage and return an input stream @param stageName stage name @param sourceFileName file path in stage @param decompress true if file compressed @return an input stream @throws SnowflakeSQLException if any SQL error occurs.
[ "Download", "file", "from", "the", "given", "stage", "and", "return", "an", "input", "stream" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeConnectionV1.java#L1100-L1179
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/EncryptionProvider.java
EncryptionProvider.decryptStream
public static InputStream decryptStream(InputStream inputStream, String keyBase64, String ivBase64, RemoteStoreFileEncryptionMaterial encMat) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException { byte[] decodedKey = Base64.decode(encMat.getQueryStageMasterKey()); byte[] keyBytes = Base64.decode(keyBase64); byte[] ivBytes = Base64.decode(ivBase64); SecretKey queryStageMasterKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, AES); Cipher keyCipher = Cipher.getInstance(KEY_CIPHER); keyCipher.init(Cipher.DECRYPT_MODE, queryStageMasterKey); byte[] fileKeyBytes = keyCipher.doFinal(keyBytes); SecretKey fileKey = new SecretKeySpec(fileKeyBytes, 0, decodedKey.length, AES); Cipher dataCipher = Cipher.getInstance(FILE_CIPHER); IvParameterSpec ivy = new IvParameterSpec(ivBytes); dataCipher.init(Cipher.DECRYPT_MODE, fileKey, ivy); return new CipherInputStream(inputStream, dataCipher); }
java
public static InputStream decryptStream(InputStream inputStream, String keyBase64, String ivBase64, RemoteStoreFileEncryptionMaterial encMat) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException { byte[] decodedKey = Base64.decode(encMat.getQueryStageMasterKey()); byte[] keyBytes = Base64.decode(keyBase64); byte[] ivBytes = Base64.decode(ivBase64); SecretKey queryStageMasterKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, AES); Cipher keyCipher = Cipher.getInstance(KEY_CIPHER); keyCipher.init(Cipher.DECRYPT_MODE, queryStageMasterKey); byte[] fileKeyBytes = keyCipher.doFinal(keyBytes); SecretKey fileKey = new SecretKeySpec(fileKeyBytes, 0, decodedKey.length, AES); Cipher dataCipher = Cipher.getInstance(FILE_CIPHER); IvParameterSpec ivy = new IvParameterSpec(ivBytes); dataCipher.init(Cipher.DECRYPT_MODE, fileKey, ivy); return new CipherInputStream(inputStream, dataCipher); }
[ "public", "static", "InputStream", "decryptStream", "(", "InputStream", "inputStream", ",", "String", "keyBase64", ",", "String", "ivBase64", ",", "RemoteStoreFileEncryptionMaterial", "encMat", ")", "throws", "NoSuchPaddingException", ",", "NoSuchAlgorithmException", ",", ...
Decrypt a InputStream
[ "Decrypt", "a", "InputStream" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/EncryptionProvider.java#L52-L86
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/EventHandler.java
EventHandler.startFlusher
synchronized void startFlusher() { // Create a new scheduled executor service with a threadfactory that // creates daemonized threads; this way if the user doesn't exit nicely // the JVM Runtime won't hang flusher = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; } }); flusher.scheduleWithFixedDelay(new QueueFlusher(), 0, flushPeriodMs, TimeUnit.MILLISECONDS); }
java
synchronized void startFlusher() { // Create a new scheduled executor service with a threadfactory that // creates daemonized threads; this way if the user doesn't exit nicely // the JVM Runtime won't hang flusher = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; } }); flusher.scheduleWithFixedDelay(new QueueFlusher(), 0, flushPeriodMs, TimeUnit.MILLISECONDS); }
[ "synchronized", "void", "startFlusher", "(", ")", "{", "// Create a new scheduled executor service with a threadfactory that", "// creates daemonized threads; this way if the user doesn't exit nicely", "// the JVM Runtime won't hang", "flusher", "=", "Executors", ".", "newScheduledThreadPo...
Creates and runs a new QueueFlusher thread
[ "Creates", "and", "runs", "a", "new", "QueueFlusher", "thread" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/EventHandler.java#L194-L217
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/EventHandler.java
EventHandler.dumpLogBuffer
public void dumpLogBuffer(String identifier) { final ArrayList<LogRecord> logBufferCopy; final PrintWriter logDumper; final OutputStream outStream; Formatter formatter = this.getFormatter(); // Check if compression of dump file is enabled boolean disableCompression = System.getProperty(DISABLE_DUMP_COMPR_PROP) != null; // If no identifying factor (eg, an incident id) was provided, get one if (identifier == null) { identifier = EventUtil.getDumpFileId(); } // Do some sanity checking to make sure we're not flooding the user's // disk with dump files cleanupSfDumps(true); String logDumpPath = logDumpPathPrefix + "/" + LOG_DUMP_FILE_NAME + identifier + LOG_DUMP_FILE_EXT; if (!disableCompression) { logDumpPath += LOG_DUMP_COMP_EXT; } logger.debug("EventHandler dumping log buffer to {}", logDumpPath); // Copy logBuffer because this is potentially long running. synchronized (this) { logBufferCopy = new ArrayList<>(logBuffer); logBuffer.clear(); } File outputFile = new File(logDumpPath); /** * Because log files could potentially be very large, we should never open * them in append mode. It's rare that this should happen anyways... */ try { // If the dump path doesn't already exist, create it. if (outputFile.getParentFile() != null) { outputFile.getParentFile().mkdirs(); } outStream = disableCompression ? new FileOutputStream(logDumpPath, false) : new GZIPOutputStream(new FileOutputStream(logDumpPath, false)); logDumper = new PrintWriter(outStream, true); } catch (IOException exc) { // Not much to do here, can't dump logs so exit out. logger.debug("Log dump failed, exception: {}", exc.getMessage()); return; } // Iterate over log entries, format them, then dump them. for (LogRecord entry : logBufferCopy) { logDumper.write(formatter != null ? formatter.format(entry) : entry.getMessage()); } // Clean up logDumper.flush(); logDumper.close(); }
java
public void dumpLogBuffer(String identifier) { final ArrayList<LogRecord> logBufferCopy; final PrintWriter logDumper; final OutputStream outStream; Formatter formatter = this.getFormatter(); // Check if compression of dump file is enabled boolean disableCompression = System.getProperty(DISABLE_DUMP_COMPR_PROP) != null; // If no identifying factor (eg, an incident id) was provided, get one if (identifier == null) { identifier = EventUtil.getDumpFileId(); } // Do some sanity checking to make sure we're not flooding the user's // disk with dump files cleanupSfDumps(true); String logDumpPath = logDumpPathPrefix + "/" + LOG_DUMP_FILE_NAME + identifier + LOG_DUMP_FILE_EXT; if (!disableCompression) { logDumpPath += LOG_DUMP_COMP_EXT; } logger.debug("EventHandler dumping log buffer to {}", logDumpPath); // Copy logBuffer because this is potentially long running. synchronized (this) { logBufferCopy = new ArrayList<>(logBuffer); logBuffer.clear(); } File outputFile = new File(logDumpPath); /** * Because log files could potentially be very large, we should never open * them in append mode. It's rare that this should happen anyways... */ try { // If the dump path doesn't already exist, create it. if (outputFile.getParentFile() != null) { outputFile.getParentFile().mkdirs(); } outStream = disableCompression ? new FileOutputStream(logDumpPath, false) : new GZIPOutputStream(new FileOutputStream(logDumpPath, false)); logDumper = new PrintWriter(outStream, true); } catch (IOException exc) { // Not much to do here, can't dump logs so exit out. logger.debug("Log dump failed, exception: {}", exc.getMessage()); return; } // Iterate over log entries, format them, then dump them. for (LogRecord entry : logBufferCopy) { logDumper.write(formatter != null ? formatter.format(entry) : entry.getMessage()); } // Clean up logDumper.flush(); logDumper.close(); }
[ "public", "void", "dumpLogBuffer", "(", "String", "identifier", ")", "{", "final", "ArrayList", "<", "LogRecord", ">", "logBufferCopy", ";", "final", "PrintWriter", "logDumper", ";", "final", "OutputStream", "outStream", ";", "Formatter", "formatter", "=", "this",...
Dumps the contents of the in-memory log buffer to disk and clears the buffer. @param identifier event id
[ "Dumps", "the", "contents", "of", "the", "in", "-", "memory", "log", "buffer", "to", "disk", "and", "clears", "the", "buffer", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/EventHandler.java#L309-L385
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/EventHandler.java
EventHandler.cleanupSfDumps
protected void cleanupSfDumps(boolean deleteOldest) { // Check what the maximum number of dumpfiles and the max allowable // aggregate dump file size is. int maxDumpFiles = System.getProperty(MAX_NUM_DUMP_FILES_PROP) != null ? Integer.valueOf(System.getProperty(MAX_NUM_DUMP_FILES_PROP)) : DEFAULT_MAX_DUMP_FILES; int maxDumpDirSizeMB = System.getProperty(MAX_SIZE_DUMPS_MB_PROP) != null ? Integer.valueOf(System.getProperty(MAX_SIZE_DUMPS_MB_PROP)) : DEFAULT_MAX_DUMPDIR_SIZE_MB; File dumpDir = new File(logDumpPathPrefix); long dirSizeBytes = 0; if (dumpDir.listFiles() == null) { return; } // Keep a sorted list of files by size as we go in case we need to // delete some TreeSet<File> fileList = new TreeSet<>(new Comparator<File>() { @Override public int compare(File a, File b) { return a.length() < b.length() ? -1 : 1; } }); // Loop over files in this directory and get rid of old ones // while accumulating the total size for (File file : dumpDir.listFiles()) { if ((!file.getName().startsWith(LOG_DUMP_FILE_NAME) && !file.getName().startsWith(IncidentUtil.INC_DUMP_FILE_NAME)) || (System.currentTimeMillis() - file.lastModified() > FILE_EXPN_TIME_MS && file.delete())) { continue; } dirSizeBytes += file.length(); fileList.add(file); } // If we're exceeding our max allotted disk usage, cut some stuff out; // else if we need to make space for a new dump delete the oldest. if (dirSizeBytes >= ((long) maxDumpDirSizeMB << 20)) { // While we take up more than half the allotted disk usage, keep deleting. for (File file : fileList) { if (dirSizeBytes < ((long) maxDumpDirSizeMB << 19)) { break; } long victimSize = file.length(); if (file.delete()) { dirSizeBytes -= victimSize; } } } else if (deleteOldest && fileList.size() >= maxDumpFiles) { fileList.first().delete(); } }
java
protected void cleanupSfDumps(boolean deleteOldest) { // Check what the maximum number of dumpfiles and the max allowable // aggregate dump file size is. int maxDumpFiles = System.getProperty(MAX_NUM_DUMP_FILES_PROP) != null ? Integer.valueOf(System.getProperty(MAX_NUM_DUMP_FILES_PROP)) : DEFAULT_MAX_DUMP_FILES; int maxDumpDirSizeMB = System.getProperty(MAX_SIZE_DUMPS_MB_PROP) != null ? Integer.valueOf(System.getProperty(MAX_SIZE_DUMPS_MB_PROP)) : DEFAULT_MAX_DUMPDIR_SIZE_MB; File dumpDir = new File(logDumpPathPrefix); long dirSizeBytes = 0; if (dumpDir.listFiles() == null) { return; } // Keep a sorted list of files by size as we go in case we need to // delete some TreeSet<File> fileList = new TreeSet<>(new Comparator<File>() { @Override public int compare(File a, File b) { return a.length() < b.length() ? -1 : 1; } }); // Loop over files in this directory and get rid of old ones // while accumulating the total size for (File file : dumpDir.listFiles()) { if ((!file.getName().startsWith(LOG_DUMP_FILE_NAME) && !file.getName().startsWith(IncidentUtil.INC_DUMP_FILE_NAME)) || (System.currentTimeMillis() - file.lastModified() > FILE_EXPN_TIME_MS && file.delete())) { continue; } dirSizeBytes += file.length(); fileList.add(file); } // If we're exceeding our max allotted disk usage, cut some stuff out; // else if we need to make space for a new dump delete the oldest. if (dirSizeBytes >= ((long) maxDumpDirSizeMB << 20)) { // While we take up more than half the allotted disk usage, keep deleting. for (File file : fileList) { if (dirSizeBytes < ((long) maxDumpDirSizeMB << 19)) { break; } long victimSize = file.length(); if (file.delete()) { dirSizeBytes -= victimSize; } } } else if (deleteOldest && fileList.size() >= maxDumpFiles) { fileList.first().delete(); } }
[ "protected", "void", "cleanupSfDumps", "(", "boolean", "deleteOldest", ")", "{", "// Check what the maximum number of dumpfiles and the max allowable", "// aggregate dump file size is.", "int", "maxDumpFiles", "=", "System", ".", "getProperty", "(", "MAX_NUM_DUMP_FILES_PROP", ")"...
Function to remove old Snowflake Dump files to make room for new ones. @param deleteOldest if true, always deletes the oldest file found if max number of dump files has been reached
[ "Function", "to", "remove", "old", "Snowflake", "Dump", "files", "to", "make", "room", "for", "new", "ones", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/EventHandler.java#L393-L466
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/EventHandler.java
EventHandler.needsToThrottle
private synchronized boolean needsToThrottle(String signature) { AtomicInteger sigCount; // Are we already throttling this signature? if (throttledIncidents.containsKey(signature)) { // Lazily check if it's time to unthrottle if (throttledIncidents.get(signature).plusHours(THROTTLE_DURATION_HRS). compareTo(DateTime.now()) <= 0) { // Start counting the # of times we've seen this again & stop throttling. throttledIncidents.remove(signature); incidentCounter.put(signature, new AtomicInteger(1)); return false; } return true; } sigCount = incidentCounter.get(signature); if (sigCount == null) { // If there isn't an entry to track this signature, make one. incidentCounter.put(signature, sigCount = new AtomicInteger(0)); } else if (sigCount.get() + 1 >= INCIDENT_THROTTLE_LIMIT_PER_HR) { // We've hit the limit so throttle. incidentCounter.remove(signature); throttledIncidents.put(signature, DateTime.now()); return true; } sigCount.incrementAndGet(); return false; }
java
private synchronized boolean needsToThrottle(String signature) { AtomicInteger sigCount; // Are we already throttling this signature? if (throttledIncidents.containsKey(signature)) { // Lazily check if it's time to unthrottle if (throttledIncidents.get(signature).plusHours(THROTTLE_DURATION_HRS). compareTo(DateTime.now()) <= 0) { // Start counting the # of times we've seen this again & stop throttling. throttledIncidents.remove(signature); incidentCounter.put(signature, new AtomicInteger(1)); return false; } return true; } sigCount = incidentCounter.get(signature); if (sigCount == null) { // If there isn't an entry to track this signature, make one. incidentCounter.put(signature, sigCount = new AtomicInteger(0)); } else if (sigCount.get() + 1 >= INCIDENT_THROTTLE_LIMIT_PER_HR) { // We've hit the limit so throttle. incidentCounter.remove(signature); throttledIncidents.put(signature, DateTime.now()); return true; } sigCount.incrementAndGet(); return false; }
[ "private", "synchronized", "boolean", "needsToThrottle", "(", "String", "signature", ")", "{", "AtomicInteger", "sigCount", ";", "// Are we already throttling this signature?", "if", "(", "throttledIncidents", ".", "containsKey", "(", "signature", ")", ")", "{", "// Laz...
Checks to see if the reporting of an incident should be throttled due to the number of times the signature has been seen in the last hour @param signature incident signature @return true if incidents needs to be throttled
[ "Checks", "to", "see", "if", "the", "reporting", "of", "an", "incident", "should", "be", "throttled", "due", "to", "the", "number", "of", "times", "the", "signature", "has", "been", "seen", "in", "the", "last", "hour" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/EventHandler.java#L504-L540
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/StreamLoader.java
StreamLoader.start
@Override public void start() { LOGGER.debug("Start Loading"); // validate parameters validateParameters(); if (_op == null) { this.abort(new ConnectionError("Loader started with no operation")); return; } initDateFormats(); initQueues(); if (_is_first_start_call) { // is this the first start call? try { if (_startTransaction) { LOGGER.debug("Begin Transaction"); _processConn.createStatement().execute("begin transaction"); } else { LOGGER.debug("No Transaction started"); } } catch (SQLException ex) { abort(new Loader.ConnectionError("Failed to start Transaction", Utils.getCause(ex))); } if (_truncate) { truncateTargetTable(); } try { if (_before != null) { LOGGER.debug("Running Execute Before SQL"); _processConn.createStatement().execute(_before); } } catch (SQLException ex) { abort(new Loader.ConnectionError( String.format("Execute Before SQL failed to run: %s", _before), Utils.getCause(ex))); } } }
java
@Override public void start() { LOGGER.debug("Start Loading"); // validate parameters validateParameters(); if (_op == null) { this.abort(new ConnectionError("Loader started with no operation")); return; } initDateFormats(); initQueues(); if (_is_first_start_call) { // is this the first start call? try { if (_startTransaction) { LOGGER.debug("Begin Transaction"); _processConn.createStatement().execute("begin transaction"); } else { LOGGER.debug("No Transaction started"); } } catch (SQLException ex) { abort(new Loader.ConnectionError("Failed to start Transaction", Utils.getCause(ex))); } if (_truncate) { truncateTargetTable(); } try { if (_before != null) { LOGGER.debug("Running Execute Before SQL"); _processConn.createStatement().execute(_before); } } catch (SQLException ex) { abort(new Loader.ConnectionError( String.format("Execute Before SQL failed to run: %s", _before), Utils.getCause(ex))); } } }
[ "@", "Override", "public", "void", "start", "(", ")", "{", "LOGGER", ".", "debug", "(", "\"Start Loading\"", ")", ";", "// validate parameters", "validateParameters", "(", ")", ";", "if", "(", "_op", "==", "null", ")", "{", "this", ".", "abort", "(", "ne...
Starts the loader
[ "Starts", "the", "loader" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/StreamLoader.java#L361-L420
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/StreamLoader.java
StreamLoader.flushQueues
private void flushQueues() { // Terminate data loading thread. LOGGER.debug("Flush Queues"); try { _queueData.put(new byte[0]); _thread.join(10000); if (_thread.isAlive()) { _thread.interrupt(); } } catch (Exception ex) { String msg = "Failed to join StreamLoader queue: " + ex.getMessage(); LOGGER.error(msg, ex); throw new DataError(msg, Utils.getCause(ex)); } // Put last stage on queue terminate(); // wait for the processing to finish _put.join(); _process.join(); if (_aborted.get()) { // Loader was aborted due to an exception. // It was rolled back at that time. //LOGGER.log(Level.WARNING, // "Loader had been previously aborted by error", _abortCause); throw _abortCause; } }
java
private void flushQueues() { // Terminate data loading thread. LOGGER.debug("Flush Queues"); try { _queueData.put(new byte[0]); _thread.join(10000); if (_thread.isAlive()) { _thread.interrupt(); } } catch (Exception ex) { String msg = "Failed to join StreamLoader queue: " + ex.getMessage(); LOGGER.error(msg, ex); throw new DataError(msg, Utils.getCause(ex)); } // Put last stage on queue terminate(); // wait for the processing to finish _put.join(); _process.join(); if (_aborted.get()) { // Loader was aborted due to an exception. // It was rolled back at that time. //LOGGER.log(Level.WARNING, // "Loader had been previously aborted by error", _abortCause); throw _abortCause; } }
[ "private", "void", "flushQueues", "(", ")", "{", "// Terminate data loading thread.", "LOGGER", ".", "debug", "(", "\"Flush Queues\"", ")", ";", "try", "{", "_queueData", ".", "put", "(", "new", "byte", "[", "0", "]", ")", ";", "_thread", ".", "join", "(",...
Flushes data by joining PUT and PROCESS queues
[ "Flushes", "data", "by", "joining", "PUT", "and", "PROCESS", "queues" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/StreamLoader.java#L613-L649
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/StreamLoader.java
StreamLoader.resetOperation
@Override public void resetOperation(Operation op) { LOGGER.debug("Reset Loader"); if (op.equals(_op)) { //no-op return; } LOGGER.debug("Operation is changing from {} to {}", _op, op); _op = op; if (_stage != null) { try { queuePut(_stage); } catch (InterruptedException ex) { LOGGER.error(_stage.getId(), ex); } } _stage = new BufferStage(this, _op, _csvFileBucketSize, _csvFileSize); }
java
@Override public void resetOperation(Operation op) { LOGGER.debug("Reset Loader"); if (op.equals(_op)) { //no-op return; } LOGGER.debug("Operation is changing from {} to {}", _op, op); _op = op; if (_stage != null) { try { queuePut(_stage); } catch (InterruptedException ex) { LOGGER.error(_stage.getId(), ex); } } _stage = new BufferStage(this, _op, _csvFileBucketSize, _csvFileSize); }
[ "@", "Override", "public", "void", "resetOperation", "(", "Operation", "op", ")", "{", "LOGGER", ".", "debug", "(", "\"Reset Loader\"", ")", ";", "if", "(", "op", ".", "equals", "(", "_op", ")", ")", "{", "//no-op", "return", ";", "}", "LOGGER", ".", ...
If operation changes, existing stage needs to be scheduled for processing.
[ "If", "operation", "changes", "existing", "stage", "needs", "to", "be", "scheduled", "for", "processing", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/StreamLoader.java#L824-L852
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/FileCacheManager.java
FileCacheManager.overrideCacheFile
void overrideCacheFile(File newCacheFile) { this.cacheFile = newCacheFile; this.cacheDir = newCacheFile.getParentFile(); this.baseCacheFileName = newCacheFile.getName(); }
java
void overrideCacheFile(File newCacheFile) { this.cacheFile = newCacheFile; this.cacheDir = newCacheFile.getParentFile(); this.baseCacheFileName = newCacheFile.getName(); }
[ "void", "overrideCacheFile", "(", "File", "newCacheFile", ")", "{", "this", ".", "cacheFile", "=", "newCacheFile", ";", "this", ".", "cacheDir", "=", "newCacheFile", ".", "getParentFile", "(", ")", ";", "this", ".", "baseCacheFileName", "=", "newCacheFile", "....
Override the cache file. @param newCacheFile a file object to override the default one.
[ "Override", "the", "cache", "file", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/FileCacheManager.java#L96-L101
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/FileCacheManager.java
FileCacheManager.readCacheFile
JsonNode readCacheFile() { if (cacheFile == null || !this.checkCacheLockFile()) { // no cache or the cache is not valid. return null; } try { if (!cacheFile.exists()) { LOGGER.debug( "Cache file doesn't exists. File: {}", cacheFile); return null; } try (Reader reader = new InputStreamReader( new FileInputStream(cacheFile), DEFAULT_FILE_ENCODING)) { return OBJECT_MAPPER.readTree(reader); } } catch (IOException ex) { LOGGER.debug( "Failed to read the cache file. No worry. File: {}, Err: {}", cacheFile, ex); } return null; }
java
JsonNode readCacheFile() { if (cacheFile == null || !this.checkCacheLockFile()) { // no cache or the cache is not valid. return null; } try { if (!cacheFile.exists()) { LOGGER.debug( "Cache file doesn't exists. File: {}", cacheFile); return null; } try (Reader reader = new InputStreamReader( new FileInputStream(cacheFile), DEFAULT_FILE_ENCODING)) { return OBJECT_MAPPER.readTree(reader); } } catch (IOException ex) { LOGGER.debug( "Failed to read the cache file. No worry. File: {}, Err: {}", cacheFile, ex); } return null; }
[ "JsonNode", "readCacheFile", "(", ")", "{", "if", "(", "cacheFile", "==", "null", "||", "!", "this", ".", "checkCacheLockFile", "(", ")", ")", "{", "// no cache or the cache is not valid.", "return", "null", ";", "}", "try", "{", "if", "(", "!", "cacheFile",...
Reads the cache file.
[ "Reads", "the", "cache", "file", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/FileCacheManager.java#L191-L220
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/FileCacheManager.java
FileCacheManager.tryLockCacheFile
private boolean tryLockCacheFile() { int cnt = 0; boolean locked = false; while (cnt < 100 && !(locked = lockCacheFile())) { try { Thread.sleep(100); } catch (InterruptedException ex) { // doesn't matter } ++cnt; } if (!locked) { LOGGER.debug("Failed to lock the cache file."); } return locked; }
java
private boolean tryLockCacheFile() { int cnt = 0; boolean locked = false; while (cnt < 100 && !(locked = lockCacheFile())) { try { Thread.sleep(100); } catch (InterruptedException ex) { // doesn't matter } ++cnt; } if (!locked) { LOGGER.debug("Failed to lock the cache file."); } return locked; }
[ "private", "boolean", "tryLockCacheFile", "(", ")", "{", "int", "cnt", "=", "0", ";", "boolean", "locked", "=", "false", ";", "while", "(", "cnt", "<", "100", "&&", "!", "(", "locked", "=", "lockCacheFile", "(", ")", ")", ")", "{", "try", "{", "Thr...
Tries to lock the cache file @return true if success or false
[ "Tries", "to", "lock", "the", "cache", "file" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/FileCacheManager.java#L280-L301
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.verifyLocalFilePath
private void verifyLocalFilePath(String localFilePathFromGS) throws SnowflakeSQLException { if (command == null) { logger.error("null command"); return; } if (command.indexOf(FILE_PROTOCOL) < 0) { logger.error( "file:// prefix not found in command: {}", command); return; } int localFilePathBeginIdx = command.indexOf(FILE_PROTOCOL) + FILE_PROTOCOL.length(); boolean isLocalFilePathQuoted = (localFilePathBeginIdx > FILE_PROTOCOL.length()) && (command.charAt(localFilePathBeginIdx - 1 - FILE_PROTOCOL.length()) == '\''); // the ending index is exclusive int localFilePathEndIdx = 0; String localFilePath = ""; if (isLocalFilePathQuoted) { // look for the matching quote localFilePathEndIdx = command.indexOf("'", localFilePathBeginIdx); if (localFilePathEndIdx > localFilePathBeginIdx) { localFilePath = command.substring(localFilePathBeginIdx, localFilePathEndIdx); } // unescape backslashes to match the file name from GS localFilePath = localFilePath.replaceAll("\\\\\\\\", "\\\\"); } else { // look for the first space or new line or semi colon List<Integer> indexList = new ArrayList<>(); char[] delimiterChars = {' ', '\n', ';'}; for (int i = 0; i < delimiterChars.length; i++) { int charIndex = command.indexOf(delimiterChars[i], localFilePathBeginIdx); if (charIndex != -1) { indexList.add(charIndex); } } localFilePathEndIdx = indexList.isEmpty() ? -1 : Collections.min(indexList); if (localFilePathEndIdx > localFilePathBeginIdx) { localFilePath = command.substring(localFilePathBeginIdx, localFilePathEndIdx); } else if (localFilePathEndIdx == -1) { localFilePath = command.substring(localFilePathBeginIdx); } } if (!localFilePath.isEmpty() && !localFilePath.equals(localFilePathFromGS)) { throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "Unexpected local file path from GS. From GS: " + localFilePathFromGS + ", expected: " + localFilePath); } else if (localFilePath.isEmpty()) { logger.debug( "fail to parse local file path from command: {}", command); } else { logger.trace( "local file path from GS matches local parsing: {}", localFilePath); } }
java
private void verifyLocalFilePath(String localFilePathFromGS) throws SnowflakeSQLException { if (command == null) { logger.error("null command"); return; } if (command.indexOf(FILE_PROTOCOL) < 0) { logger.error( "file:// prefix not found in command: {}", command); return; } int localFilePathBeginIdx = command.indexOf(FILE_PROTOCOL) + FILE_PROTOCOL.length(); boolean isLocalFilePathQuoted = (localFilePathBeginIdx > FILE_PROTOCOL.length()) && (command.charAt(localFilePathBeginIdx - 1 - FILE_PROTOCOL.length()) == '\''); // the ending index is exclusive int localFilePathEndIdx = 0; String localFilePath = ""; if (isLocalFilePathQuoted) { // look for the matching quote localFilePathEndIdx = command.indexOf("'", localFilePathBeginIdx); if (localFilePathEndIdx > localFilePathBeginIdx) { localFilePath = command.substring(localFilePathBeginIdx, localFilePathEndIdx); } // unescape backslashes to match the file name from GS localFilePath = localFilePath.replaceAll("\\\\\\\\", "\\\\"); } else { // look for the first space or new line or semi colon List<Integer> indexList = new ArrayList<>(); char[] delimiterChars = {' ', '\n', ';'}; for (int i = 0; i < delimiterChars.length; i++) { int charIndex = command.indexOf(delimiterChars[i], localFilePathBeginIdx); if (charIndex != -1) { indexList.add(charIndex); } } localFilePathEndIdx = indexList.isEmpty() ? -1 : Collections.min(indexList); if (localFilePathEndIdx > localFilePathBeginIdx) { localFilePath = command.substring(localFilePathBeginIdx, localFilePathEndIdx); } else if (localFilePathEndIdx == -1) { localFilePath = command.substring(localFilePathBeginIdx); } } if (!localFilePath.isEmpty() && !localFilePath.equals(localFilePathFromGS)) { throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "Unexpected local file path from GS. From GS: " + localFilePathFromGS + ", expected: " + localFilePath); } else if (localFilePath.isEmpty()) { logger.debug( "fail to parse local file path from command: {}", command); } else { logger.trace( "local file path from GS matches local parsing: {}", localFilePath); } }
[ "private", "void", "verifyLocalFilePath", "(", "String", "localFilePathFromGS", ")", "throws", "SnowflakeSQLException", "{", "if", "(", "command", "==", "null", ")", "{", "logger", ".", "error", "(", "\"null command\"", ")", ";", "return", ";", "}", "if", "(",...
A helper method to verify if the local file path from GS matches what's parsed locally. This is for security purpose as documented in SNOW-15153. @param localFilePathFromGS the local file path to verify @throws SnowflakeSQLException
[ "A", "helper", "method", "to", "verify", "if", "the", "local", "file", "path", "from", "GS", "matches", "what", "s", "parsed", "locally", ".", "This", "is", "for", "security", "purpose", "as", "documented", "in", "SNOW", "-", "15153", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L1189-L1271
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.uploadStream
private void uploadStream() throws SnowflakeSQLException { try { threadExecutor = SnowflakeUtil.createDefaultExecutorService( "sf-stream-upload-worker-", 1); RemoteStoreFileEncryptionMaterial encMat = encryptionMaterial.get(0); if (commandType == CommandType.UPLOAD) { threadExecutor.submit(getUploadFileCallable( stageInfo, SRC_FILE_NAME_FOR_STREAM, fileMetadataMap.get(SRC_FILE_NAME_FOR_STREAM), (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) ? null : storageFactory.createClient(stageInfo, parallel, encMat), connection, command, sourceStream, true, parallel, null, encMat)); } else if (commandType == CommandType.DOWNLOAD) { throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode()); } threadExecutor.shutdown(); try { // wait for all threads to complete without timeout threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new SnowflakeSQLException(SqlState.QUERY_CANCELED, ErrorCode.INTERRUPTED.getMessageCode()); } logger.debug("Done with uploading from a stream"); } finally { if (threadExecutor != null) { threadExecutor.shutdownNow(); threadExecutor = null; } } }
java
private void uploadStream() throws SnowflakeSQLException { try { threadExecutor = SnowflakeUtil.createDefaultExecutorService( "sf-stream-upload-worker-", 1); RemoteStoreFileEncryptionMaterial encMat = encryptionMaterial.get(0); if (commandType == CommandType.UPLOAD) { threadExecutor.submit(getUploadFileCallable( stageInfo, SRC_FILE_NAME_FOR_STREAM, fileMetadataMap.get(SRC_FILE_NAME_FOR_STREAM), (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) ? null : storageFactory.createClient(stageInfo, parallel, encMat), connection, command, sourceStream, true, parallel, null, encMat)); } else if (commandType == CommandType.DOWNLOAD) { throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode()); } threadExecutor.shutdown(); try { // wait for all threads to complete without timeout threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new SnowflakeSQLException(SqlState.QUERY_CANCELED, ErrorCode.INTERRUPTED.getMessageCode()); } logger.debug("Done with uploading from a stream"); } finally { if (threadExecutor != null) { threadExecutor.shutdownNow(); threadExecutor = null; } } }
[ "private", "void", "uploadStream", "(", ")", "throws", "SnowflakeSQLException", "{", "try", "{", "threadExecutor", "=", "SnowflakeUtil", ".", "createDefaultExecutorService", "(", "\"sf-stream-upload-worker-\"", ",", "1", ")", ";", "RemoteStoreFileEncryptionMaterial", "enc...
Helper to upload data from a stream
[ "Helper", "to", "upload", "data", "from", "a", "stream" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L1434-L1480
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.downloadStream
InputStream downloadStream(String fileName) throws SnowflakeSQLException { if (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) { logger.error("downloadStream function doesn't support local file system"); throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "downloadStream function only supported in remote stages"); } remoteLocation remoteLocation = extractLocationAndPath(stageInfo.getLocation()); String stageFilePath = fileName; if (!remoteLocation.path.isEmpty()) { stageFilePath = SnowflakeUtil.concatFilePathNames(remoteLocation.path, fileName, "/"); } RemoteStoreFileEncryptionMaterial encMat = srcFileToEncMat.get(fileName); return storageFactory.createClient(stageInfo, parallel, encMat) .downloadToStream(connection, command, parallel, remoteLocation.location, stageFilePath, stageInfo.getRegion()); }
java
InputStream downloadStream(String fileName) throws SnowflakeSQLException { if (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) { logger.error("downloadStream function doesn't support local file system"); throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "downloadStream function only supported in remote stages"); } remoteLocation remoteLocation = extractLocationAndPath(stageInfo.getLocation()); String stageFilePath = fileName; if (!remoteLocation.path.isEmpty()) { stageFilePath = SnowflakeUtil.concatFilePathNames(remoteLocation.path, fileName, "/"); } RemoteStoreFileEncryptionMaterial encMat = srcFileToEncMat.get(fileName); return storageFactory.createClient(stageInfo, parallel, encMat) .downloadToStream(connection, command, parallel, remoteLocation.location, stageFilePath, stageInfo.getRegion()); }
[ "InputStream", "downloadStream", "(", "String", "fileName", ")", "throws", "SnowflakeSQLException", "{", "if", "(", "stageInfo", ".", "getStageType", "(", ")", "==", "StageInfo", ".", "StageType", ".", "LOCAL_FS", ")", "{", "logger", ".", "error", "(", "\"down...
Download a file from remote, and return an input stream
[ "Download", "a", "file", "from", "remote", "and", "return", "an", "input", "stream" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L1485-L1512
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.downloadFiles
private void downloadFiles() throws SnowflakeSQLException { try { threadExecutor = SnowflakeUtil.createDefaultExecutorService( "sf-file-download-worker-", 1); for (String srcFile : sourceFiles) { FileMetadata fileMetadata = fileMetadataMap.get(srcFile); // Check if the result status is already set so that we don't need to // upload it if (fileMetadata.resultStatus != ResultStatus.UNKNOWN) { logger.debug("Skipping {}, status: {}, details: {}", srcFile, fileMetadata.resultStatus, fileMetadata.errorDetails); continue; } RemoteStoreFileEncryptionMaterial encMat = srcFileToEncMat.get(srcFile); threadExecutor.submit(getDownloadFileCallable( stageInfo, srcFile, localLocation, fileMetadataMap, (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) ? null : storageFactory.createClient(stageInfo, parallel, encMat), connection, command, parallel, encMat)); logger.debug("submitted download job for: {}", srcFile); } threadExecutor.shutdown(); try { // wait for all threads to complete without timeout threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new SnowflakeSQLException(SqlState.QUERY_CANCELED, ErrorCode.INTERRUPTED.getMessageCode()); } logger.debug("Done with downloading"); } finally { if (threadExecutor != null) { threadExecutor.shutdownNow(); threadExecutor = null; } } }
java
private void downloadFiles() throws SnowflakeSQLException { try { threadExecutor = SnowflakeUtil.createDefaultExecutorService( "sf-file-download-worker-", 1); for (String srcFile : sourceFiles) { FileMetadata fileMetadata = fileMetadataMap.get(srcFile); // Check if the result status is already set so that we don't need to // upload it if (fileMetadata.resultStatus != ResultStatus.UNKNOWN) { logger.debug("Skipping {}, status: {}, details: {}", srcFile, fileMetadata.resultStatus, fileMetadata.errorDetails); continue; } RemoteStoreFileEncryptionMaterial encMat = srcFileToEncMat.get(srcFile); threadExecutor.submit(getDownloadFileCallable( stageInfo, srcFile, localLocation, fileMetadataMap, (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) ? null : storageFactory.createClient(stageInfo, parallel, encMat), connection, command, parallel, encMat)); logger.debug("submitted download job for: {}", srcFile); } threadExecutor.shutdown(); try { // wait for all threads to complete without timeout threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new SnowflakeSQLException(SqlState.QUERY_CANCELED, ErrorCode.INTERRUPTED.getMessageCode()); } logger.debug("Done with downloading"); } finally { if (threadExecutor != null) { threadExecutor.shutdownNow(); threadExecutor = null; } } }
[ "private", "void", "downloadFiles", "(", ")", "throws", "SnowflakeSQLException", "{", "try", "{", "threadExecutor", "=", "SnowflakeUtil", ".", "createDefaultExecutorService", "(", "\"sf-file-download-worker-\"", ",", "1", ")", ";", "for", "(", "String", "srcFile", "...
Helper to download files from remote
[ "Helper", "to", "download", "files", "from", "remote" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L1517-L1575
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.uploadFiles
private void uploadFiles(Set<String> fileList, int parallel) throws SnowflakeSQLException { try { threadExecutor = SnowflakeUtil.createDefaultExecutorService( "sf-file-upload-worker-", parallel); for (String srcFile : fileList) { FileMetadata fileMetadata = fileMetadataMap.get(srcFile); // Check if the result status is already set so that we don't need to // upload it if (fileMetadata.resultStatus != ResultStatus.UNKNOWN) { logger.debug("Skipping {}, status: {}, details: {}", srcFile, fileMetadata.resultStatus, fileMetadata.errorDetails); continue; } /** * For small files, we upload files in parallel, so we don't * want the remote store uploader to upload parts in parallel for each file. * For large files, we upload them in serial, and we want remote store uploader * to upload parts in parallel for each file. This is the reason * for the parallel value. */ File srcFileObj = new File(srcFile); threadExecutor.submit(getUploadFileCallable( stageInfo, srcFile, fileMetadata, (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) ? null : storageFactory.createClient(stageInfo, parallel, encryptionMaterial.get(0)), connection, command, null, false, (parallel > 1 ? 1 : this.parallel), srcFileObj, encryptionMaterial.get(0))); logger.debug("submitted copy job for: {}", srcFile); } // shut down the thread executor threadExecutor.shutdown(); try { // wait for all threads to complete without timeout threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new SnowflakeSQLException(SqlState.QUERY_CANCELED, ErrorCode.INTERRUPTED.getMessageCode()); } logger.debug("Done with uploading"); } finally { // shut down the thread pool in any case if (threadExecutor != null) { threadExecutor.shutdownNow(); threadExecutor = null; } } }
java
private void uploadFiles(Set<String> fileList, int parallel) throws SnowflakeSQLException { try { threadExecutor = SnowflakeUtil.createDefaultExecutorService( "sf-file-upload-worker-", parallel); for (String srcFile : fileList) { FileMetadata fileMetadata = fileMetadataMap.get(srcFile); // Check if the result status is already set so that we don't need to // upload it if (fileMetadata.resultStatus != ResultStatus.UNKNOWN) { logger.debug("Skipping {}, status: {}, details: {}", srcFile, fileMetadata.resultStatus, fileMetadata.errorDetails); continue; } /** * For small files, we upload files in parallel, so we don't * want the remote store uploader to upload parts in parallel for each file. * For large files, we upload them in serial, and we want remote store uploader * to upload parts in parallel for each file. This is the reason * for the parallel value. */ File srcFileObj = new File(srcFile); threadExecutor.submit(getUploadFileCallable( stageInfo, srcFile, fileMetadata, (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) ? null : storageFactory.createClient(stageInfo, parallel, encryptionMaterial.get(0)), connection, command, null, false, (parallel > 1 ? 1 : this.parallel), srcFileObj, encryptionMaterial.get(0))); logger.debug("submitted copy job for: {}", srcFile); } // shut down the thread executor threadExecutor.shutdown(); try { // wait for all threads to complete without timeout threadExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException ex) { throw new SnowflakeSQLException(SqlState.QUERY_CANCELED, ErrorCode.INTERRUPTED.getMessageCode()); } logger.debug("Done with uploading"); } finally { // shut down the thread pool in any case if (threadExecutor != null) { threadExecutor.shutdownNow(); threadExecutor = null; } } }
[ "private", "void", "uploadFiles", "(", "Set", "<", "String", ">", "fileList", ",", "int", "parallel", ")", "throws", "SnowflakeSQLException", "{", "try", "{", "threadExecutor", "=", "SnowflakeUtil", ".", "createDefaultExecutorService", "(", "\"sf-file-upload-worker-\"...
This method create a thread pool based on requested number of threads and upload the files using the thread pool. @param fileList The set of files to upload @param parallel degree of parallelism for the upload @throws SnowflakeSQLException
[ "This", "method", "create", "a", "thread", "pool", "based", "on", "requested", "number", "of", "threads", "and", "upload", "the", "files", "using", "the", "thread", "pool", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L1585-L1654
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.expandFileNames
static public Set<String> expandFileNames(String[] filePathList) throws SnowflakeSQLException { Set<String> result = new HashSet<String>(); // a location to file pattern map so that we only need to list the // same directory once when they appear in multiple times. Map<String, List<String>> locationToFilePatterns; locationToFilePatterns = new HashMap<String, List<String>>(); String cwd = System.getProperty("user.dir"); for (String path : filePathList) { // replace ~ with user home path = path.replace("~", System.getProperty("user.home")); // user may also specify files relative to current directory // add the current path if that is the case if (!(new File(path)).isAbsolute()) { logger.debug("Adding current working dir to relative file path."); path = cwd + localFSFileSep + path; } // check if the path contains any wildcards if (!path.contains("*") && !path.contains("?") && !(path.contains("[") && path.contains("]"))) { /* this file path doesn't have any wildcard, so we don't need to * expand it */ result.add(path); } else { // get the directory path int lastFileSepIndex = path.lastIndexOf(localFSFileSep); // SNOW-15203: if we don't find a default file sep, try "/" if it is not // the default file sep. if (lastFileSepIndex < 0 && !"/".equals(localFSFileSep)) { lastFileSepIndex = path.lastIndexOf("/"); } String loc = path.substring(0, lastFileSepIndex + 1); String filePattern = path.substring(lastFileSepIndex + 1); List<String> filePatterns = locationToFilePatterns.get(loc); if (filePatterns == null) { filePatterns = new ArrayList<String>(); locationToFilePatterns.put(loc, filePatterns); } filePatterns.add(filePattern); } } // For each location, list files and match against the patterns for (Map.Entry<String, List<String>> entry : locationToFilePatterns.entrySet()) { try { java.io.File dir = new java.io.File(entry.getKey()); logger.debug("Listing files under: {} with patterns: {}", entry.getKey(), entry.getValue().toString()); // The following currently ignore sub directories for (Object file : FileUtils.listFiles(dir, new WildcardFileFilter(entry.getValue()), null)) { result.add(((java.io.File) file).getCanonicalPath()); } } catch (Exception ex) { throw new SnowflakeSQLException(ex, SqlState.DATA_EXCEPTION, ErrorCode.FAIL_LIST_FILES.getMessageCode(), "Exception: " + ex.getMessage() + ", Dir=" + entry.getKey() + ", Patterns=" + entry.getValue().toString()); } } logger.debug("Expanded file paths: "); for (String filePath : result) { logger.debug("file: {}", filePath); } return result; }
java
static public Set<String> expandFileNames(String[] filePathList) throws SnowflakeSQLException { Set<String> result = new HashSet<String>(); // a location to file pattern map so that we only need to list the // same directory once when they appear in multiple times. Map<String, List<String>> locationToFilePatterns; locationToFilePatterns = new HashMap<String, List<String>>(); String cwd = System.getProperty("user.dir"); for (String path : filePathList) { // replace ~ with user home path = path.replace("~", System.getProperty("user.home")); // user may also specify files relative to current directory // add the current path if that is the case if (!(new File(path)).isAbsolute()) { logger.debug("Adding current working dir to relative file path."); path = cwd + localFSFileSep + path; } // check if the path contains any wildcards if (!path.contains("*") && !path.contains("?") && !(path.contains("[") && path.contains("]"))) { /* this file path doesn't have any wildcard, so we don't need to * expand it */ result.add(path); } else { // get the directory path int lastFileSepIndex = path.lastIndexOf(localFSFileSep); // SNOW-15203: if we don't find a default file sep, try "/" if it is not // the default file sep. if (lastFileSepIndex < 0 && !"/".equals(localFSFileSep)) { lastFileSepIndex = path.lastIndexOf("/"); } String loc = path.substring(0, lastFileSepIndex + 1); String filePattern = path.substring(lastFileSepIndex + 1); List<String> filePatterns = locationToFilePatterns.get(loc); if (filePatterns == null) { filePatterns = new ArrayList<String>(); locationToFilePatterns.put(loc, filePatterns); } filePatterns.add(filePattern); } } // For each location, list files and match against the patterns for (Map.Entry<String, List<String>> entry : locationToFilePatterns.entrySet()) { try { java.io.File dir = new java.io.File(entry.getKey()); logger.debug("Listing files under: {} with patterns: {}", entry.getKey(), entry.getValue().toString()); // The following currently ignore sub directories for (Object file : FileUtils.listFiles(dir, new WildcardFileFilter(entry.getValue()), null)) { result.add(((java.io.File) file).getCanonicalPath()); } } catch (Exception ex) { throw new SnowflakeSQLException(ex, SqlState.DATA_EXCEPTION, ErrorCode.FAIL_LIST_FILES.getMessageCode(), "Exception: " + ex.getMessage() + ", Dir=" + entry.getKey() + ", Patterns=" + entry.getValue().toString()); } } logger.debug("Expanded file paths: "); for (String filePath : result) { logger.debug("file: {}", filePath); } return result; }
[ "static", "public", "Set", "<", "String", ">", "expandFileNames", "(", "String", "[", "]", "filePathList", ")", "throws", "SnowflakeSQLException", "{", "Set", "<", "String", ">", "result", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "// a loc...
process a list of file paths separated by "," and expand the wildcards if any to generate the list of paths for all files matched by the wildcards @param filePathList file path list @return a set of file names that is matched @throws SnowflakeSQLException if cannot find the file
[ "process", "a", "list", "of", "file", "paths", "separated", "by", "and", "expand", "the", "wildcards", "if", "any", "to", "generate", "the", "list", "of", "paths", "for", "all", "files", "matched", "by", "the", "wildcards" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L1704-L1805
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.mimeTypeToCompressionType
private FileCompressionType mimeTypeToCompressionType(String mimeTypeStr) throws MimeTypeParseException { MimeType mimeType = null; if (mimeTypeStr != null) { mimeType = new MimeType(mimeTypeStr); } if (mimeType != null && mimeType.getSubType() != null) { return FileCompressionType.lookupByMimeSubType( mimeType.getSubType().toLowerCase()); } return null; }
java
private FileCompressionType mimeTypeToCompressionType(String mimeTypeStr) throws MimeTypeParseException { MimeType mimeType = null; if (mimeTypeStr != null) { mimeType = new MimeType(mimeTypeStr); } if (mimeType != null && mimeType.getSubType() != null) { return FileCompressionType.lookupByMimeSubType( mimeType.getSubType().toLowerCase()); } return null; }
[ "private", "FileCompressionType", "mimeTypeToCompressionType", "(", "String", "mimeTypeStr", ")", "throws", "MimeTypeParseException", "{", "MimeType", "mimeType", "=", "null", ";", "if", "(", "mimeTypeStr", "!=", "null", ")", "{", "mimeType", "=", "new", "MimeType",...
Derive compression type from mime type @param mimeTypeStr @return @throws MimeTypeParseException
[ "Derive", "compression", "type", "from", "mime", "type" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L2510-L2527
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.getMimeTypeFromFileExtension
private String getMimeTypeFromFileExtension(String srcFile) { String srcFileLowCase = srcFile.toLowerCase(); for (FileCompressionType compressionType : FileCompressionType.values()) { if (srcFileLowCase.endsWith(compressionType.fileExtension)) { return compressionType.mimeType + "/" + compressionType.mimeSubTypes.get(0); } } return null; }
java
private String getMimeTypeFromFileExtension(String srcFile) { String srcFileLowCase = srcFile.toLowerCase(); for (FileCompressionType compressionType : FileCompressionType.values()) { if (srcFileLowCase.endsWith(compressionType.fileExtension)) { return compressionType.mimeType + "/" + compressionType.mimeSubTypes.get(0); } } return null; }
[ "private", "String", "getMimeTypeFromFileExtension", "(", "String", "srcFile", ")", "{", "String", "srcFileLowCase", "=", "srcFile", ".", "toLowerCase", "(", ")", ";", "for", "(", "FileCompressionType", "compressionType", ":", "FileCompressionType", ".", "values", "...
Derive mime type from file extension @param srcFile @return
[ "Derive", "mime", "type", "from", "file", "extension" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L2753-L2767
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.extractLocationAndPath
static public remoteLocation extractLocationAndPath(String stageLocationPath) { String location = stageLocationPath; String path = ""; // split stage location as location name and path if (stageLocationPath.contains("/")) { location = stageLocationPath.substring(0, stageLocationPath.indexOf("/")); path = stageLocationPath.substring(stageLocationPath.indexOf("/") + 1); } return new remoteLocation(location, path); }
java
static public remoteLocation extractLocationAndPath(String stageLocationPath) { String location = stageLocationPath; String path = ""; // split stage location as location name and path if (stageLocationPath.contains("/")) { location = stageLocationPath.substring(0, stageLocationPath.indexOf("/")); path = stageLocationPath.substring(stageLocationPath.indexOf("/") + 1); } return new remoteLocation(location, path); }
[ "static", "public", "remoteLocation", "extractLocationAndPath", "(", "String", "stageLocationPath", ")", "{", "String", "location", "=", "stageLocationPath", ";", "String", "path", "=", "\"\"", ";", "// split stage location as location name and path", "if", "(", "stageLoc...
A small helper for extracting location name and path from full location path @param stageLocationPath stage location @return remoteLocation object
[ "A", "small", "helper", "for", "extracting", "location", "name", "and", "path", "from", "full", "location", "path" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L2775-L2788
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.describeColumns
@Override public List<SnowflakeColumnMetadata> describeColumns() throws Exception { return SnowflakeUtil.describeFixedViewColumns( commandType == CommandType.UPLOAD ? (showEncryptionParameter ? UploadCommandEncryptionFacade.class : UploadCommandFacade.class) : (showEncryptionParameter ? DownloadCommandEncryptionFacade.class : DownloadCommandFacade.class)); }
java
@Override public List<SnowflakeColumnMetadata> describeColumns() throws Exception { return SnowflakeUtil.describeFixedViewColumns( commandType == CommandType.UPLOAD ? (showEncryptionParameter ? UploadCommandEncryptionFacade.class : UploadCommandFacade.class) : (showEncryptionParameter ? DownloadCommandEncryptionFacade.class : DownloadCommandFacade.class)); }
[ "@", "Override", "public", "List", "<", "SnowflakeColumnMetadata", ">", "describeColumns", "(", ")", "throws", "Exception", "{", "return", "SnowflakeUtil", ".", "describeFixedViewColumns", "(", "commandType", "==", "CommandType", ".", "UPLOAD", "?", "(", "showEncryp...
Describe the metadata of a fixed view. @return list of column meta data @throws Exception failed to construct list
[ "Describe", "the", "metadata", "of", "a", "fixed", "view", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L2796-L2805
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java
SnowflakeFileTransferAgent.populateStatusRows
private void populateStatusRows() { for (Map.Entry<String, FileMetadata> entry : fileMetadataMap.entrySet()) { FileMetadata fileMetadata = entry.getValue(); if (commandType == CommandType.UPLOAD) { statusRows.add(showEncryptionParameter ? new UploadCommandEncryptionFacade( fileMetadata.srcFileName, fileMetadata.destFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.srcFileSize, fileMetadata.destFileSize, (fileMetadata.srcCompressionType == null) ? "NONE" : fileMetadata.srcCompressionType.name(), (fileMetadata.destCompressionType == null) ? "NONE" : fileMetadata.destCompressionType.name(), fileMetadata.isEncrypted) : new UploadCommandFacade( fileMetadata.srcFileName, fileMetadata.destFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.srcFileSize, fileMetadata.destFileSize, (fileMetadata.srcCompressionType == null) ? "NONE" : fileMetadata.srcCompressionType.name(), (fileMetadata.destCompressionType == null) ? "NONE" : fileMetadata.destCompressionType.name())); } else if (commandType == CommandType.DOWNLOAD) { statusRows.add(showEncryptionParameter ? new DownloadCommandEncryptionFacade( fileMetadata.srcFileName.startsWith("/") ? fileMetadata.srcFileName.substring(1) : fileMetadata.srcFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.destFileSize, fileMetadata.isEncrypted) : new DownloadCommandFacade( fileMetadata.srcFileName.startsWith("/") ? fileMetadata.srcFileName.substring(1) : fileMetadata.srcFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.destFileSize)); } } /* we sort the result if the connection is in sorting mode */ Object sortProperty = null; sortProperty = connection.getSFSessionProperty("sort"); boolean sortResult = sortProperty != null && (Boolean) sortProperty; if (sortResult) { Comparator comparator = (commandType == CommandType.UPLOAD) ? new Comparator<Object>() { public int compare(Object a, Object b) { String srcFileNameA = ((UploadCommandFacade) a).srcFile; String srcFileNameB = ((UploadCommandFacade) b).srcFile; return srcFileNameA.compareTo(srcFileNameB); } } : new Comparator<Object>() { public int compare(Object a, Object b) { String srcFileNameA = ((DownloadCommandFacade) a).file; String srcFileNameB = ((DownloadCommandFacade) b).file; return srcFileNameA.compareTo(srcFileNameB); } }; // sort the rows by source file names Collections.sort(statusRows, comparator); } }
java
private void populateStatusRows() { for (Map.Entry<String, FileMetadata> entry : fileMetadataMap.entrySet()) { FileMetadata fileMetadata = entry.getValue(); if (commandType == CommandType.UPLOAD) { statusRows.add(showEncryptionParameter ? new UploadCommandEncryptionFacade( fileMetadata.srcFileName, fileMetadata.destFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.srcFileSize, fileMetadata.destFileSize, (fileMetadata.srcCompressionType == null) ? "NONE" : fileMetadata.srcCompressionType.name(), (fileMetadata.destCompressionType == null) ? "NONE" : fileMetadata.destCompressionType.name(), fileMetadata.isEncrypted) : new UploadCommandFacade( fileMetadata.srcFileName, fileMetadata.destFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.srcFileSize, fileMetadata.destFileSize, (fileMetadata.srcCompressionType == null) ? "NONE" : fileMetadata.srcCompressionType.name(), (fileMetadata.destCompressionType == null) ? "NONE" : fileMetadata.destCompressionType.name())); } else if (commandType == CommandType.DOWNLOAD) { statusRows.add(showEncryptionParameter ? new DownloadCommandEncryptionFacade( fileMetadata.srcFileName.startsWith("/") ? fileMetadata.srcFileName.substring(1) : fileMetadata.srcFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.destFileSize, fileMetadata.isEncrypted) : new DownloadCommandFacade( fileMetadata.srcFileName.startsWith("/") ? fileMetadata.srcFileName.substring(1) : fileMetadata.srcFileName, fileMetadata.resultStatus.name(), fileMetadata.errorDetails, fileMetadata.destFileSize)); } } /* we sort the result if the connection is in sorting mode */ Object sortProperty = null; sortProperty = connection.getSFSessionProperty("sort"); boolean sortResult = sortProperty != null && (Boolean) sortProperty; if (sortResult) { Comparator comparator = (commandType == CommandType.UPLOAD) ? new Comparator<Object>() { public int compare(Object a, Object b) { String srcFileNameA = ((UploadCommandFacade) a).srcFile; String srcFileNameB = ((UploadCommandFacade) b).srcFile; return srcFileNameA.compareTo(srcFileNameB); } } : new Comparator<Object>() { public int compare(Object a, Object b) { String srcFileNameA = ((DownloadCommandFacade) a).file; String srcFileNameB = ((DownloadCommandFacade) b).file; return srcFileNameA.compareTo(srcFileNameB); } }; // sort the rows by source file names Collections.sort(statusRows, comparator); } }
[ "private", "void", "populateStatusRows", "(", ")", "{", "for", "(", "Map", ".", "Entry", "<", "String", ",", "FileMetadata", ">", "entry", ":", "fileMetadataMap", ".", "entrySet", "(", ")", ")", "{", "FileMetadata", "fileMetadata", "=", "entry", ".", "getV...
Generate status rows for each file
[ "Generate", "status", "rows", "for", "each", "file" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java#L2829-L2921
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/Incident.java
Incident.flush
@Override public void flush() { ObjectMapper mapper = ObjectMapperFactory.getObjectMapper(); String dtoDump; URI incidentURI; try { dtoDump = mapper.writeValueAsString(new IncidentV2DTO(this)); } catch (JsonProcessingException ex) { logger.error("Incident registration failed, could not map " + "incident report to json string. Exception: {}", ex.getMessage()); return; } // Sanity check... Preconditions.checkNotNull(dtoDump); try { URIBuilder uriBuilder = new URIBuilder(this.serverUrl); uriBuilder.setPath(SF_PATH_CREATE_INCIDENT_V2); incidentURI = uriBuilder.build(); } catch (URISyntaxException ex) { logger.error("Incident registration failed, " + "URI could not be built. Exception: {}", ex.getMessage()); return; } HttpPost postRequest = new HttpPost(incidentURI); postRequest.setHeader(SFSession.SF_HEADER_AUTHORIZATION, SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + " " + SFSession.SF_HEADER_TOKEN_TAG + "=\"" + this.sessionToken + "\""); // Compress the payload. ByteArrayEntity input = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); byte[] bytes = dtoDump.getBytes(StandardCharsets.UTF_8); gzos.write(bytes); gzos.finish(); input = new ByteArrayEntity(baos.toByteArray()); input.setContentType("application/json"); } catch (IOException exc) { logger.debug("Incident registration failed, could not compress" + " payload. Exception: {}", exc.getMessage()); } postRequest.setEntity(input); postRequest.addHeader("content-encoding", "gzip"); try { String response = HttpUtil.executeRequest(postRequest, 1000, 0, null); logger.debug("Incident registration was successful. Response: '{}'", response); } catch (Exception ex) { // No much we can do here besides complain. logger.error( "Incident registration request failed, exception: {}", ex.getMessage()); } }
java
@Override public void flush() { ObjectMapper mapper = ObjectMapperFactory.getObjectMapper(); String dtoDump; URI incidentURI; try { dtoDump = mapper.writeValueAsString(new IncidentV2DTO(this)); } catch (JsonProcessingException ex) { logger.error("Incident registration failed, could not map " + "incident report to json string. Exception: {}", ex.getMessage()); return; } // Sanity check... Preconditions.checkNotNull(dtoDump); try { URIBuilder uriBuilder = new URIBuilder(this.serverUrl); uriBuilder.setPath(SF_PATH_CREATE_INCIDENT_V2); incidentURI = uriBuilder.build(); } catch (URISyntaxException ex) { logger.error("Incident registration failed, " + "URI could not be built. Exception: {}", ex.getMessage()); return; } HttpPost postRequest = new HttpPost(incidentURI); postRequest.setHeader(SFSession.SF_HEADER_AUTHORIZATION, SFSession.SF_HEADER_SNOWFLAKE_AUTHTYPE + " " + SFSession.SF_HEADER_TOKEN_TAG + "=\"" + this.sessionToken + "\""); // Compress the payload. ByteArrayEntity input = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); byte[] bytes = dtoDump.getBytes(StandardCharsets.UTF_8); gzos.write(bytes); gzos.finish(); input = new ByteArrayEntity(baos.toByteArray()); input.setContentType("application/json"); } catch (IOException exc) { logger.debug("Incident registration failed, could not compress" + " payload. Exception: {}", exc.getMessage()); } postRequest.setEntity(input); postRequest.addHeader("content-encoding", "gzip"); try { String response = HttpUtil.executeRequest(postRequest, 1000, 0, null); logger.debug("Incident registration was successful. Response: '{}'", response); } catch (Exception ex) { // No much we can do here besides complain. logger.error( "Incident registration request failed, exception: {}", ex.getMessage()); } }
[ "@", "Override", "public", "void", "flush", "(", ")", "{", "ObjectMapper", "mapper", "=", "ObjectMapperFactory", ".", "getObjectMapper", "(", ")", ";", "String", "dtoDump", ";", "URI", "incidentURI", ";", "try", "{", "dtoDump", "=", "mapper", ".", "writeValu...
Sends incident to GS to log
[ "Sends", "incident", "to", "GS", "to", "log" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/Incident.java#L173-L249
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFSSLConnectionSocketFactory.java
SFSSLConnectionSocketFactory.decideCipherSuites
private static String[] decideCipherSuites() { String sysCipherSuites = System.getProperty("https.cipherSuites"); String[] cipherSuites = sysCipherSuites != null ? sysCipherSuites.split(",") : // use jdk default cipher suites ((SSLServerSocketFactory) SSLServerSocketFactory.getDefault()) .getDefaultCipherSuites(); // cipher suites need to be picked up in code explicitly for jdk 1.7 // https://stackoverflow.com/questions/44378970/ if (logger.isTraceEnabled()) { logger.trace("Cipher suites used: {}", Arrays.toString(cipherSuites)); } return cipherSuites; }
java
private static String[] decideCipherSuites() { String sysCipherSuites = System.getProperty("https.cipherSuites"); String[] cipherSuites = sysCipherSuites != null ? sysCipherSuites.split(",") : // use jdk default cipher suites ((SSLServerSocketFactory) SSLServerSocketFactory.getDefault()) .getDefaultCipherSuites(); // cipher suites need to be picked up in code explicitly for jdk 1.7 // https://stackoverflow.com/questions/44378970/ if (logger.isTraceEnabled()) { logger.trace("Cipher suites used: {}", Arrays.toString(cipherSuites)); } return cipherSuites; }
[ "private", "static", "String", "[", "]", "decideCipherSuites", "(", ")", "{", "String", "sysCipherSuites", "=", "System", ".", "getProperty", "(", "\"https.cipherSuites\"", ")", ";", "String", "[", "]", "cipherSuites", "=", "sysCipherSuites", "!=", "null", "?", ...
Decide cipher suites that will be passed into the SSLConnectionSocketFactory @return List of cipher suites.
[ "Decide", "cipher", "suites", "that", "will", "be", "passed", "into", "the", "SSLConnectionSocketFactory" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFSSLConnectionSocketFactory.java#L71-L88
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java
Telemetry.createTelemetry
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; } }
java
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; } }
[ "public", "static", "Telemetry", "createTelemetry", "(", "Connection", "conn", ",", "int", "flushSize", ")", "{", "try", "{", "return", "createTelemetry", "(", "conn", ".", "unwrap", "(", "SnowflakeConnectionV1", ".", "class", ")", ".", "getSfSession", "(", ")...
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
[ "Initialize", "the", "telemetry", "connector" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java#L105-L116
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java
Telemetry.addLogToBatch
public void addLogToBatch(TelemetryData log) throws IOException { if (isClosed) { throw new IOException("Telemetry connector is closed"); } if (!isTelemetryEnabled()) { return; // if disable, do nothing } synchronized (locker) { this.logBatch.add(log); } if (this.logBatch.size() >= this.forceFlushSize) { this.sendBatch(); } }
java
public void addLogToBatch(TelemetryData log) throws IOException { if (isClosed) { throw new IOException("Telemetry connector is closed"); } if (!isTelemetryEnabled()) { return; // if disable, do nothing } synchronized (locker) { this.logBatch.add(log); } if (this.logBatch.size() >= this.forceFlushSize) { this.sendBatch(); } }
[ "public", "void", "addLogToBatch", "(", "TelemetryData", "log", ")", "throws", "IOException", "{", "if", "(", "isClosed", ")", "{", "throw", "new", "IOException", "(", "\"Telemetry connector is closed\"", ")", ";", "}", "if", "(", "!", "isTelemetryEnabled", "(",...
Add log to batch to be submitted to telemetry. Send batch if forceFlushSize reached @param log entry to add @throws IOException if closed or uploading batch fails
[ "Add", "log", "to", "batch", "to", "be", "submitted", "to", "telemetry", ".", "Send", "batch", "if", "forceFlushSize", "reached" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java#L160-L180
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java
Telemetry.tryAddLogToBatch
public void tryAddLogToBatch(TelemetryData log) { try { addLogToBatch(log); } catch (IOException ex) { logger.debug("Exception encountered while sending metrics to telemetry endpoint.", ex); } }
java
public void tryAddLogToBatch(TelemetryData log) { try { addLogToBatch(log); } catch (IOException ex) { logger.debug("Exception encountered while sending metrics to telemetry endpoint.", ex); } }
[ "public", "void", "tryAddLogToBatch", "(", "TelemetryData", "log", ")", "{", "try", "{", "addLogToBatch", "(", "log", ")", ";", "}", "catch", "(", "IOException", "ex", ")", "{", "logger", ".", "debug", "(", "\"Exception encountered while sending metrics to telemet...
Attempt to add log to batch, and suppress exceptions thrown in case of failure @param log entry to add
[ "Attempt", "to", "add", "log", "to", "batch", "and", "suppress", "exceptions", "thrown", "in", "case", "of", "failure" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java#L202-L212
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java
Telemetry.close
public void close() throws IOException { if (isClosed) { throw new IOException("Telemetry connector is closed"); } try { this.sendBatch(); } catch (IOException e) { logger.error("Send logs failed on closing", e); } finally { this.isClosed = true; } }
java
public void close() throws IOException { if (isClosed) { throw new IOException("Telemetry connector is closed"); } try { this.sendBatch(); } catch (IOException e) { logger.error("Send logs failed on closing", e); } finally { this.isClosed = true; } }
[ "public", "void", "close", "(", ")", "throws", "IOException", "{", "if", "(", "isClosed", ")", "{", "throw", "new", "IOException", "(", "\"Telemetry connector is closed\"", ")", ";", "}", "try", "{", "this", ".", "sendBatch", "(", ")", ";", "}", "catch", ...
Close telemetry connector and send any unsubmitted logs @throws IOException if closed or uploading batch fails
[ "Close", "telemetry", "connector", "and", "send", "any", "unsubmitted", "logs" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java#L219-L237
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java
Telemetry.sendBatch
public boolean sendBatch() throws IOException { if (isClosed) { throw new IOException("Telemetry connector is closed"); } if (!isTelemetryEnabled()) { return false; } LinkedList<TelemetryData> tmpList; synchronized (locker) { tmpList = this.logBatch; this.logBatch = new LinkedList<>(); } if (session.isClosed()) { throw new UnexpectedException("Session is closed when sending log"); } if (!tmpList.isEmpty()) { //session shared with JDBC String sessionToken = this.session.getSessionToken(); HttpPost post = new HttpPost(this.telemetryUrl); post.setEntity(new StringEntity(logsToString(tmpList))); post.setHeader("Content-type", "application/json"); post.setHeader("Authorization", "Snowflake Token=\"" + sessionToken + "\""); String response = null; try { response = HttpUtil.executeRequest(post, 1000, 0, null); } catch (SnowflakeSQLException e) { disableTelemetry(); // when got error like 404 or bad request, disable telemetry in this telemetry instance logger.error( "Telemetry request failed, " + "response: {}, exception: {}", response, e.getMessage()); return false; } } return true; }
java
public boolean sendBatch() throws IOException { if (isClosed) { throw new IOException("Telemetry connector is closed"); } if (!isTelemetryEnabled()) { return false; } LinkedList<TelemetryData> tmpList; synchronized (locker) { tmpList = this.logBatch; this.logBatch = new LinkedList<>(); } if (session.isClosed()) { throw new UnexpectedException("Session is closed when sending log"); } if (!tmpList.isEmpty()) { //session shared with JDBC String sessionToken = this.session.getSessionToken(); HttpPost post = new HttpPost(this.telemetryUrl); post.setEntity(new StringEntity(logsToString(tmpList))); post.setHeader("Content-type", "application/json"); post.setHeader("Authorization", "Snowflake Token=\"" + sessionToken + "\""); String response = null; try { response = HttpUtil.executeRequest(post, 1000, 0, null); } catch (SnowflakeSQLException e) { disableTelemetry(); // when got error like 404 or bad request, disable telemetry in this telemetry instance logger.error( "Telemetry request failed, " + "response: {}, exception: {}", response, e.getMessage()); return false; } } return true; }
[ "public", "boolean", "sendBatch", "(", ")", "throws", "IOException", "{", "if", "(", "isClosed", ")", "{", "throw", "new", "IOException", "(", "\"Telemetry connector is closed\"", ")", ";", "}", "if", "(", "!", "isTelemetryEnabled", "(", ")", ")", "{", "retu...
Send all cached logs to server @return whether the logs were sent successfully @throws IOException if closed or uploading batch fails
[ "Send", "all", "cached", "logs", "to", "server" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java#L255-L305
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java
Telemetry.logsToJson
static ObjectNode logsToJson(LinkedList<TelemetryData> telemetryData) { ObjectNode node = mapper.createObjectNode(); ArrayNode logs = mapper.createArrayNode(); for (TelemetryData data : telemetryData) { logs.add(data.toJson()); } node.set("logs", logs); return node; }
java
static ObjectNode logsToJson(LinkedList<TelemetryData> telemetryData) { ObjectNode node = mapper.createObjectNode(); ArrayNode logs = mapper.createArrayNode(); for (TelemetryData data : telemetryData) { logs.add(data.toJson()); } node.set("logs", logs); return node; }
[ "static", "ObjectNode", "logsToJson", "(", "LinkedList", "<", "TelemetryData", ">", "telemetryData", ")", "{", "ObjectNode", "node", "=", "mapper", ".", "createObjectNode", "(", ")", ";", "ArrayNode", "logs", "=", "mapper", ".", "createArrayNode", "(", ")", ";...
convert a list of log to a JSON object @param telemetryData a list of log @return the result json string
[ "convert", "a", "list", "of", "log", "to", "a", "JSON", "object" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/telemetry/Telemetry.java#L340-L351
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeStatementV1.java
SnowflakeStatementV1.executeQuery
@Override public ResultSet executeQuery(String sql) throws SQLException { raiseSQLExceptionIfStatementIsClosed(); return executeQueryInternal(sql, null); }
java
@Override public ResultSet executeQuery(String sql) throws SQLException { raiseSQLExceptionIfStatementIsClosed(); return executeQueryInternal(sql, null); }
[ "@", "Override", "public", "ResultSet", "executeQuery", "(", "String", "sql", ")", "throws", "SQLException", "{", "raiseSQLExceptionIfStatementIsClosed", "(", ")", ";", "return", "executeQueryInternal", "(", "sql", ",", "null", ")", ";", "}" ]
Execute SQL query @param sql sql statement @return ResultSet @throws SQLException if @link{#executeQueryInternal(String, Map)} throws an exception
[ "Execute", "SQL", "query" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeStatementV1.java#L159-L164
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeStatementV1.java
SnowflakeStatementV1.executeQueryInternal
ResultSet executeQueryInternal( String sql, Map<String, ParameterBindingDTO> parameterBindings) throws SQLException { SFBaseResultSet sfResultSet; try { sfResultSet = sfStatement.execute(sql, parameterBindings, SFStatement.CallingMethod.EXECUTE_QUERY); sfResultSet.setSession(this.connection.getSfSession()); } catch (SFException ex) { throw new SnowflakeSQLException(ex.getCause(), ex.getSqlState(), ex.getVendorCode(), ex.getParams()); } if (resultSet != null) { openResultSets.add(resultSet); } resultSet = new SnowflakeResultSetV1(sfResultSet, this); return getResultSet(); }
java
ResultSet executeQueryInternal( String sql, Map<String, ParameterBindingDTO> parameterBindings) throws SQLException { SFBaseResultSet sfResultSet; try { sfResultSet = sfStatement.execute(sql, parameterBindings, SFStatement.CallingMethod.EXECUTE_QUERY); sfResultSet.setSession(this.connection.getSfSession()); } catch (SFException ex) { throw new SnowflakeSQLException(ex.getCause(), ex.getSqlState(), ex.getVendorCode(), ex.getParams()); } if (resultSet != null) { openResultSets.add(resultSet); } resultSet = new SnowflakeResultSetV1(sfResultSet, this); return getResultSet(); }
[ "ResultSet", "executeQueryInternal", "(", "String", "sql", ",", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "parameterBindings", ")", "throws", "SQLException", "{", "SFBaseResultSet", "sfResultSet", ";", "try", "{", "sfResultSet", "=", "sfStatement", ".",...
Internal method for executing a query with bindings accepted. @param sql sql statement @param parameterBindings parameters bindings @return query result set @throws SQLException if @link{SFStatement.execute(String)} throws exception
[ "Internal", "method", "for", "executing", "a", "query", "with", "bindings", "accepted", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeStatementV1.java#L232-L257
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeStatementV1.java
SnowflakeStatementV1.setParameter
void setParameter(String name, Object value) throws Exception { logger.debug("public void setParameter"); try { if (this.sfStatement != null) { this.sfStatement.addProperty(name, value); } } catch (SFException ex) { throw new SnowflakeSQLException(ex); } }
java
void setParameter(String name, Object value) throws Exception { logger.debug("public void setParameter"); try { if (this.sfStatement != null) { this.sfStatement.addProperty(name, value); } } catch (SFException ex) { throw new SnowflakeSQLException(ex); } }
[ "void", "setParameter", "(", "String", "name", ",", "Object", "value", ")", "throws", "Exception", "{", "logger", ".", "debug", "(", "\"public void setParameter\"", ")", ";", "try", "{", "if", "(", "this", ".", "sfStatement", "!=", "null", ")", "{", "this"...
Sets a parameter at the statement level. Used for internal testing. @param name parameter name. @param value parameter value. @throws Exception if any SQL error occurs.
[ "Sets", "a", "parameter", "at", "the", "statement", "level", ".", "Used", "for", "internal", "testing", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeStatementV1.java#L766-L781
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java
SnowflakeChunkDownloader.createChunkDownloaderExecutorService
private static ThreadPoolExecutor createChunkDownloaderExecutorService( final String threadNamePrefix, final int parallel) { ThreadFactory threadFactory = new ThreadFactory() { private int threadCount = 1; public Thread newThread(final Runnable r) { final Thread thread = new Thread(r); thread.setName(threadNamePrefix + threadCount++); thread.setUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { logger.error( "uncaughtException in thread: " + t + " {}", e); } }); thread.setDaemon(true); return thread; } }; return (ThreadPoolExecutor) Executors.newFixedThreadPool(parallel, threadFactory); }
java
private static ThreadPoolExecutor createChunkDownloaderExecutorService( final String threadNamePrefix, final int parallel) { ThreadFactory threadFactory = new ThreadFactory() { private int threadCount = 1; public Thread newThread(final Runnable r) { final Thread thread = new Thread(r); thread.setName(threadNamePrefix + threadCount++); thread.setUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { logger.error( "uncaughtException in thread: " + t + " {}", e); } }); thread.setDaemon(true); return thread; } }; return (ThreadPoolExecutor) Executors.newFixedThreadPool(parallel, threadFactory); }
[ "private", "static", "ThreadPoolExecutor", "createChunkDownloaderExecutorService", "(", "final", "String", "threadNamePrefix", ",", "final", "int", "parallel", ")", "{", "ThreadFactory", "threadFactory", "=", "new", "ThreadFactory", "(", ")", "{", "private", "int", "t...
Create a pool of downloader threads. @param threadNamePrefix name of threads in pool @param parallel number of thread in pool @return new thread pool
[ "Create", "a", "pool", "of", "downloader", "threads", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java#L154-L184
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java
SnowflakeChunkDownloader.startNextDownloaders
private void startNextDownloaders() throws SnowflakeSQLException { long waitingTime = BASE_WAITING_MS; // submit the chunks to be downloaded up to the prefetch slot capacity // and limited by memory while (nextChunkToDownload - nextChunkToConsume < prefetchSlots && nextChunkToDownload < chunks.size()) { // check if memory limit allows more prefetching final SnowflakeResultChunk nextChunk = chunks.get(nextChunkToDownload); final long neededChunkMemory = nextChunk.computeNeededChunkMemory(); // each time only one thread can enter this block synchronized (currentMemoryUsage) { // make sure memoryLimit > neededChunkMemory; otherwise, the thread hangs if (neededChunkMemory > memoryLimit) { if (logger.isDebugEnabled()) { logger.debug("{}: reset memoryLimit from {} MB to current chunk size {} MB", Thread.currentThread().getName(), memoryLimit / 1024 / 1024, neededChunkMemory / 1024 / 1024); } memoryLimit = neededChunkMemory; } // no memory allocate when memory is not enough for prefetch if (currentMemoryUsage + neededChunkMemory > memoryLimit && nextChunkToDownload - nextChunkToConsume > 0) { break; } // only allocate memory when the future usage is less than the limit if (currentMemoryUsage + neededChunkMemory <= memoryLimit) { nextChunk.tryReuse(chunkDataCache); currentMemoryUsage += neededChunkMemory; if (logger.isDebugEnabled()) { logger.debug("{}: currentMemoryUsage in MB: {}, nextChunkToDownload: {}, nextChunkToConsume: {}, " + "newReservedMemory in B: {} ", Thread.currentThread().getName(), currentMemoryUsage / 1024 / 1024, nextChunkToDownload, nextChunkToConsume, neededChunkMemory); } logger.debug("submit chunk #{} for downloading, url={}", this.nextChunkToDownload, nextChunk.getUrl()); executor.submit(getDownloadChunkCallable(this, nextChunk, qrmk, nextChunkToDownload, chunkHeadersMap, networkTimeoutInMilli, useJsonParserV2)); // increment next chunk to download nextChunkToDownload++; // make sure reset waiting time waitingTime = BASE_WAITING_MS; // go to next chunk continue; } } // waiting when nextChunkToDownload is equal to nextChunkToConsume but reach memory limit try { waitingTime *= WAITING_SECS_MULTIPLIER; waitingTime = waitingTime > MAX_WAITING_MS ? MAX_WAITING_MS : waitingTime; long jitter = ThreadLocalRandom.current().nextLong(0, waitingTime / WAITING_JITTER_RATIO); waitingTime += jitter; if (logger.isDebugEnabled()) { logger.debug("{} waiting for {}s: currentMemoryUsage in MB: {}, neededChunkMemory in MB: {}, " + "nextChunkToDownload: {}, nextChunkToConsume: {} ", Thread.currentThread().getName(), waitingTime / 1000.0, currentMemoryUsage / 1024 / 1024, neededChunkMemory / 1024 / 1024, nextChunkToDownload, nextChunkToConsume); } Thread.sleep(waitingTime); } catch (InterruptedException ie) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "Waiting SnowflakeChunkDownloader has been interrupted."); } } // clear the cache, we can't download more at the moment // so we won't need them in the near future chunkDataCache.clear(); }
java
private void startNextDownloaders() throws SnowflakeSQLException { long waitingTime = BASE_WAITING_MS; // submit the chunks to be downloaded up to the prefetch slot capacity // and limited by memory while (nextChunkToDownload - nextChunkToConsume < prefetchSlots && nextChunkToDownload < chunks.size()) { // check if memory limit allows more prefetching final SnowflakeResultChunk nextChunk = chunks.get(nextChunkToDownload); final long neededChunkMemory = nextChunk.computeNeededChunkMemory(); // each time only one thread can enter this block synchronized (currentMemoryUsage) { // make sure memoryLimit > neededChunkMemory; otherwise, the thread hangs if (neededChunkMemory > memoryLimit) { if (logger.isDebugEnabled()) { logger.debug("{}: reset memoryLimit from {} MB to current chunk size {} MB", Thread.currentThread().getName(), memoryLimit / 1024 / 1024, neededChunkMemory / 1024 / 1024); } memoryLimit = neededChunkMemory; } // no memory allocate when memory is not enough for prefetch if (currentMemoryUsage + neededChunkMemory > memoryLimit && nextChunkToDownload - nextChunkToConsume > 0) { break; } // only allocate memory when the future usage is less than the limit if (currentMemoryUsage + neededChunkMemory <= memoryLimit) { nextChunk.tryReuse(chunkDataCache); currentMemoryUsage += neededChunkMemory; if (logger.isDebugEnabled()) { logger.debug("{}: currentMemoryUsage in MB: {}, nextChunkToDownload: {}, nextChunkToConsume: {}, " + "newReservedMemory in B: {} ", Thread.currentThread().getName(), currentMemoryUsage / 1024 / 1024, nextChunkToDownload, nextChunkToConsume, neededChunkMemory); } logger.debug("submit chunk #{} for downloading, url={}", this.nextChunkToDownload, nextChunk.getUrl()); executor.submit(getDownloadChunkCallable(this, nextChunk, qrmk, nextChunkToDownload, chunkHeadersMap, networkTimeoutInMilli, useJsonParserV2)); // increment next chunk to download nextChunkToDownload++; // make sure reset waiting time waitingTime = BASE_WAITING_MS; // go to next chunk continue; } } // waiting when nextChunkToDownload is equal to nextChunkToConsume but reach memory limit try { waitingTime *= WAITING_SECS_MULTIPLIER; waitingTime = waitingTime > MAX_WAITING_MS ? MAX_WAITING_MS : waitingTime; long jitter = ThreadLocalRandom.current().nextLong(0, waitingTime / WAITING_JITTER_RATIO); waitingTime += jitter; if (logger.isDebugEnabled()) { logger.debug("{} waiting for {}s: currentMemoryUsage in MB: {}, neededChunkMemory in MB: {}, " + "nextChunkToDownload: {}, nextChunkToConsume: {} ", Thread.currentThread().getName(), waitingTime / 1000.0, currentMemoryUsage / 1024 / 1024, neededChunkMemory / 1024 / 1024, nextChunkToDownload, nextChunkToConsume); } Thread.sleep(waitingTime); } catch (InterruptedException ie) { throw new SnowflakeSQLException( SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "Waiting SnowflakeChunkDownloader has been interrupted."); } } // clear the cache, we can't download more at the moment // so we won't need them in the near future chunkDataCache.clear(); }
[ "private", "void", "startNextDownloaders", "(", ")", "throws", "SnowflakeSQLException", "{", "long", "waitingTime", "=", "BASE_WAITING_MS", ";", "// submit the chunks to be downloaded up to the prefetch slot capacity", "// and limited by memory", "while", "(", "nextChunkToDownload"...
Submit download chunk tasks to executor. Number depends on thread and memory limit
[ "Submit", "download", "chunk", "tasks", "to", "executor", ".", "Number", "depends", "on", "thread", "and", "memory", "limit" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java#L310-L414
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java
SnowflakeChunkDownloader.releaseAllChunkMemoryUsage
public void releaseAllChunkMemoryUsage() { if (chunks == null || chunks.size() == 0) { return; } for (int i = 0; i < chunks.size(); i++) { releaseCurrentMemoryUsage(i, chunks.get(i).computeNeededChunkMemory()); } }
java
public void releaseAllChunkMemoryUsage() { if (chunks == null || chunks.size() == 0) { return; } for (int i = 0; i < chunks.size(); i++) { releaseCurrentMemoryUsage(i, chunks.get(i).computeNeededChunkMemory()); } }
[ "public", "void", "releaseAllChunkMemoryUsage", "(", ")", "{", "if", "(", "chunks", "==", "null", "||", "chunks", ".", "size", "(", ")", "==", "0", ")", "{", "return", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "chunks", ".", "siz...
release all existing chunk memory usage before close
[ "release", "all", "existing", "chunk", "memory", "usage", "before", "close" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java#L436-L447
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java
SnowflakeChunkDownloader.logOutOfMemoryError
private void logOutOfMemoryError() { logger.error("Dump some crucial information below:\n" + "Total milliseconds waiting for chunks: {},\n" + "Total memory used: {}, Max heap size: {}, total download time: {} millisec,\n" + "total parsing time: {} milliseconds, total chunks: {},\n" + "currentMemoryUsage in Byte: {}, currentMemoryLimit in Bytes: {} \n" + "nextChunkToDownload: {}, nextChunkToConsume: {}\n" + "Several suggestions to try to resolve the OOM issue:\n" + "1. increase the JVM heap size if you have more space; or \n" + "2. use CLIENT_MEMORY_LIMIT to reduce the memory usage by the JDBC driver " + "(https://docs.snowflake.net/manuals/sql-reference/parameters.html#client-memory-limit)" + "3. please make sure 2 * CLIENT_PREFETCH_THREADS * CLIENT_RESULT_CHUNK_SIZE < CLIENT_MEMORY_LIMIT. " + "If not, please reduce CLIENT_PREFETCH_THREADS and CLIENT_RESULT_CHUNK_SIZE too.", numberMillisWaitingForChunks, Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory(), totalMillisDownloadingChunks.get(), totalMillisParsingChunks.get(), chunks.size(), currentMemoryUsage, memoryLimit, nextChunkToDownload, nextChunkToConsume); }
java
private void logOutOfMemoryError() { logger.error("Dump some crucial information below:\n" + "Total milliseconds waiting for chunks: {},\n" + "Total memory used: {}, Max heap size: {}, total download time: {} millisec,\n" + "total parsing time: {} milliseconds, total chunks: {},\n" + "currentMemoryUsage in Byte: {}, currentMemoryLimit in Bytes: {} \n" + "nextChunkToDownload: {}, nextChunkToConsume: {}\n" + "Several suggestions to try to resolve the OOM issue:\n" + "1. increase the JVM heap size if you have more space; or \n" + "2. use CLIENT_MEMORY_LIMIT to reduce the memory usage by the JDBC driver " + "(https://docs.snowflake.net/manuals/sql-reference/parameters.html#client-memory-limit)" + "3. please make sure 2 * CLIENT_PREFETCH_THREADS * CLIENT_RESULT_CHUNK_SIZE < CLIENT_MEMORY_LIMIT. " + "If not, please reduce CLIENT_PREFETCH_THREADS and CLIENT_RESULT_CHUNK_SIZE too.", numberMillisWaitingForChunks, Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory(), totalMillisDownloadingChunks.get(), totalMillisParsingChunks.get(), chunks.size(), currentMemoryUsage, memoryLimit, nextChunkToDownload, nextChunkToConsume); }
[ "private", "void", "logOutOfMemoryError", "(", ")", "{", "logger", ".", "error", "(", "\"Dump some crucial information below:\\n\"", "+", "\"Total milliseconds waiting for chunks: {},\\n\"", "+", "\"Total memory used: {}, Max heap size: {}, total download time: {} millisec,\\n\"", "+",...
log out of memory error and provide the suggestion to avoid this error
[ "log", "out", "of", "memory", "error", "and", "provide", "the", "suggestion", "to", "avoid", "this", "error" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java#L611-L630
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java
SnowflakeChunkDownloader.terminate
public Metrics terminate() { if (!terminated) { logger.debug("Total milliseconds waiting for chunks: {}, " + "Total memory used: {}, total download time: {} millisec, " + "total parsing time: {} milliseconds, total chunks: {}", numberMillisWaitingForChunks, Runtime.getRuntime().totalMemory(), totalMillisDownloadingChunks.get(), totalMillisParsingChunks.get(), chunks.size()); if (executor != null) { executor.shutdownNow(); executor = null; } chunks = null; chunkDataCache.clear(); terminated = true; return new Metrics(); } return null; }
java
public Metrics terminate() { if (!terminated) { logger.debug("Total milliseconds waiting for chunks: {}, " + "Total memory used: {}, total download time: {} millisec, " + "total parsing time: {} milliseconds, total chunks: {}", numberMillisWaitingForChunks, Runtime.getRuntime().totalMemory(), totalMillisDownloadingChunks.get(), totalMillisParsingChunks.get(), chunks.size()); if (executor != null) { executor.shutdownNow(); executor = null; } chunks = null; chunkDataCache.clear(); terminated = true; return new Metrics(); } return null; }
[ "public", "Metrics", "terminate", "(", ")", "{", "if", "(", "!", "terminated", ")", "{", "logger", ".", "debug", "(", "\"Total milliseconds waiting for chunks: {}, \"", "+", "\"Total memory used: {}, total download time: {} millisec, \"", "+", "\"total parsing time: {} millis...
terminate the downloader @return chunk downloader metrics collected over instance lifetime
[ "terminate", "the", "downloader" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/SnowflakeChunkDownloader.java#L637-L661
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/util/SecretDetector.java
SecretDetector.maskAWSSecret
public static String maskAWSSecret(String sql) { List<SecretDetector.SecretRange> secretRanges = SecretDetector.getAWSSecretPos(sql); for (SecretDetector.SecretRange secretRange : secretRanges) { sql = maskText(sql, secretRange.beginPos, secretRange.endPos); } return sql; }
java
public static String maskAWSSecret(String sql) { List<SecretDetector.SecretRange> secretRanges = SecretDetector.getAWSSecretPos(sql); for (SecretDetector.SecretRange secretRange : secretRanges) { sql = maskText(sql, secretRange.beginPos, secretRange.endPos); } return sql; }
[ "public", "static", "String", "maskAWSSecret", "(", "String", "sql", ")", "{", "List", "<", "SecretDetector", ".", "SecretRange", ">", "secretRanges", "=", "SecretDetector", ".", "getAWSSecretPos", "(", "sql", ")", ";", "for", "(", "SecretDetector", ".", "Secr...
mask AWS secret in the input string @param sql @return masked string
[ "mask", "AWS", "secret", "in", "the", "input", "string" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/util/SecretDetector.java#L136-L145
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFStatement.java
SFStatement.sanityCheckQuery
private void sanityCheckQuery(String sql) throws SQLException { if (sql == null || sql.isEmpty()) { throw new SnowflakeSQLException(SqlState.SQL_STATEMENT_NOT_YET_COMPLETE, ErrorCode.INVALID_SQL.getMessageCode(), sql); } }
java
private void sanityCheckQuery(String sql) throws SQLException { if (sql == null || sql.isEmpty()) { throw new SnowflakeSQLException(SqlState.SQL_STATEMENT_NOT_YET_COMPLETE, ErrorCode.INVALID_SQL.getMessageCode(), sql); } }
[ "private", "void", "sanityCheckQuery", "(", "String", "sql", ")", "throws", "SQLException", "{", "if", "(", "sql", "==", "null", "||", "sql", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "SnowflakeSQLException", "(", "SqlState", ".", "SQL_STATEMENT_NO...
Sanity check query text @param sql The SQL statement to check @throws SQLException
[ "Sanity", "check", "query", "text" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFStatement.java#L135-L143
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFStatement.java
SFStatement.executeQuery
private SFBaseResultSet executeQuery( String sql, Map<String, ParameterBindingDTO> parametersBinding, boolean describeOnly, CallingMethod caller) throws SQLException, SFException { sanityCheckQuery(sql); String trimmedSql = sql.trim(); // snowflake specific client side commands if (isFileTransfer(trimmedSql)) { // PUT/GET command logger.debug("Executing file transfer locally: {}", sql); return executeFileTransfer(sql); } // NOTE: It is intentional two describeOnly parameters are specified. return executeQueryInternal( sql, parametersBinding, describeOnly, describeOnly, // internal query if describeOnly is true caller ); }
java
private SFBaseResultSet executeQuery( String sql, Map<String, ParameterBindingDTO> parametersBinding, boolean describeOnly, CallingMethod caller) throws SQLException, SFException { sanityCheckQuery(sql); String trimmedSql = sql.trim(); // snowflake specific client side commands if (isFileTransfer(trimmedSql)) { // PUT/GET command logger.debug("Executing file transfer locally: {}", sql); return executeFileTransfer(sql); } // NOTE: It is intentional two describeOnly parameters are specified. return executeQueryInternal( sql, parametersBinding, describeOnly, describeOnly, // internal query if describeOnly is true caller ); }
[ "private", "SFBaseResultSet", "executeQuery", "(", "String", "sql", ",", "Map", "<", "String", ",", "ParameterBindingDTO", ">", "parametersBinding", ",", "boolean", "describeOnly", ",", "CallingMethod", "caller", ")", "throws", "SQLException", ",", "SFException", "{...
Execute SQL query with an option for describe only @param sql sql statement @param describeOnly true if describe only @return query result set @throws SQLException if connection is already closed @throws SFException if result set is null
[ "Execute", "SQL", "query", "with", "an", "option", "for", "describe", "only" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFStatement.java#L154-L182
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFStatement.java
SFStatement.describe
public SFStatementMetaData describe(String sql) throws SFException, SQLException { SFBaseResultSet baseResultSet = executeQuery(sql, null, true, null); describeJobUUID = baseResultSet.getQueryId(); return new SFStatementMetaData(baseResultSet.getMetaData(), baseResultSet.getStatementType(), baseResultSet.getNumberOfBinds(), baseResultSet.isArrayBindSupported()); }
java
public SFStatementMetaData describe(String sql) throws SFException, SQLException { SFBaseResultSet baseResultSet = executeQuery(sql, null, true, null); describeJobUUID = baseResultSet.getQueryId(); return new SFStatementMetaData(baseResultSet.getMetaData(), baseResultSet.getStatementType(), baseResultSet.getNumberOfBinds(), baseResultSet.isArrayBindSupported()); }
[ "public", "SFStatementMetaData", "describe", "(", "String", "sql", ")", "throws", "SFException", ",", "SQLException", "{", "SFBaseResultSet", "baseResultSet", "=", "executeQuery", "(", "sql", ",", "null", ",", "true", ",", "null", ")", ";", "describeJobUUID", "=...
Describe a statement @param sql statement @return metadata of statement including result set metadata and binding information @throws SQLException if connection is already closed @throws SFException if result set is null
[ "Describe", "a", "statement" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFStatement.java#L192-L202
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFStatement.java
SFStatement.setTimeBomb
private void setTimeBomb(ScheduledExecutorService executor) { class TimeBombTask implements Callable<Void> { private final SFStatement statement; private TimeBombTask(SFStatement statement) { this.statement = statement; } @Override public Void call() throws SQLException { try { statement.cancel(); } catch (SFException ex) { throw new SnowflakeSQLException(ex, ex.getSqlState(), ex.getVendorCode(), ex.getParams()); } return null; } } executor.schedule(new TimeBombTask(this), this.queryTimeout, TimeUnit.SECONDS); }
java
private void setTimeBomb(ScheduledExecutorService executor) { class TimeBombTask implements Callable<Void> { private final SFStatement statement; private TimeBombTask(SFStatement statement) { this.statement = statement; } @Override public Void call() throws SQLException { try { statement.cancel(); } catch (SFException ex) { throw new SnowflakeSQLException(ex, ex.getSqlState(), ex.getVendorCode(), ex.getParams()); } return null; } } executor.schedule(new TimeBombTask(this), this.queryTimeout, TimeUnit.SECONDS); }
[ "private", "void", "setTimeBomb", "(", "ScheduledExecutorService", "executor", ")", "{", "class", "TimeBombTask", "implements", "Callable", "<", "Void", ">", "{", "private", "final", "SFStatement", "statement", ";", "private", "TimeBombTask", "(", "SFStatement", "st...
Set a time bomb to cancel the outstanding query when timeout is reached. @param executor object to execute statement cancel request
[ "Set", "a", "time", "bomb", "to", "cancel", "the", "outstanding", "query", "when", "timeout", "is", "reached", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFStatement.java#L316-L346
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFStatement.java
SFStatement.cancelHelper
private void cancelHelper(String sql, String mediaType) throws SnowflakeSQLException, SFException { synchronized (this) { if (isClosed) { throw new SFException(ErrorCode.INTERNAL_ERROR, "statement already closed"); } } StmtUtil.StmtInput stmtInput = new StmtUtil.StmtInput(); stmtInput.setServerUrl(session.getServerUrl()) .setSql(sql) .setMediaType(mediaType) .setRequestId(requestId) .setSessionToken(session.getSessionToken()) .setServiceName(session.getServiceName()); StmtUtil.cancel(stmtInput); synchronized (this) { /* * done with the remote execution of the query. set sequenceId to -1 * and request id to null so that we don't try to abort it again upon * canceling. */ this.sequenceId = -1; this.requestId = null; } }
java
private void cancelHelper(String sql, String mediaType) throws SnowflakeSQLException, SFException { synchronized (this) { if (isClosed) { throw new SFException(ErrorCode.INTERNAL_ERROR, "statement already closed"); } } StmtUtil.StmtInput stmtInput = new StmtUtil.StmtInput(); stmtInput.setServerUrl(session.getServerUrl()) .setSql(sql) .setMediaType(mediaType) .setRequestId(requestId) .setSessionToken(session.getSessionToken()) .setServiceName(session.getServiceName()); StmtUtil.cancel(stmtInput); synchronized (this) { /* * done with the remote execution of the query. set sequenceId to -1 * and request id to null so that we don't try to abort it again upon * canceling. */ this.sequenceId = -1; this.requestId = null; } }
[ "private", "void", "cancelHelper", "(", "String", "sql", ",", "String", "mediaType", ")", "throws", "SnowflakeSQLException", ",", "SFException", "{", "synchronized", "(", "this", ")", "{", "if", "(", "isClosed", ")", "{", "throw", "new", "SFException", "(", ...
A helper method to build URL and cancel the SQL for exec @param sql sql statement @param mediaType media type @throws SnowflakeSQLException if failed to cancel the statement @throws SFException if statement is already closed
[ "A", "helper", "method", "to", "build", "URL", "and", "cancel", "the", "SQL", "for", "exec" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFStatement.java#L601-L633
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/SFStatement.java
SFStatement.getMoreResults
public boolean getMoreResults(int current) throws SQLException { // clean up current result, if exists if (resultSet != null && (current == Statement.CLOSE_CURRENT_RESULT || current == Statement.CLOSE_ALL_RESULTS)) { resultSet.close(); } resultSet = null; // verify if more results exist if (childResults == null || childResults.isEmpty()) { return false; } // fetch next result using the query id SFChildResult nextResult = childResults.remove(0); try { JsonNode result = StmtUtil.getQueryResultJSON( nextResult.getId(), session); Object sortProperty = session.getSFSessionProperty("sort"); boolean sortResult = sortProperty != null && (Boolean) sortProperty; resultSet = new SFResultSet(result, this, sortResult); // override statement type so we can treat the result set like a result of // the original statement called (and not the result scan) resultSet.setStatementType(nextResult.getType()); return nextResult.getType().isGenerateResultSet(); } catch (SFException ex) { throw new SnowflakeSQLException(ex); } }
java
public boolean getMoreResults(int current) throws SQLException { // clean up current result, if exists if (resultSet != null && (current == Statement.CLOSE_CURRENT_RESULT || current == Statement.CLOSE_ALL_RESULTS)) { resultSet.close(); } resultSet = null; // verify if more results exist if (childResults == null || childResults.isEmpty()) { return false; } // fetch next result using the query id SFChildResult nextResult = childResults.remove(0); try { JsonNode result = StmtUtil.getQueryResultJSON( nextResult.getId(), session); Object sortProperty = session.getSFSessionProperty("sort"); boolean sortResult = sortProperty != null && (Boolean) sortProperty; resultSet = new SFResultSet(result, this, sortResult); // override statement type so we can treat the result set like a result of // the original statement called (and not the result scan) resultSet.setStatementType(nextResult.getType()); return nextResult.getType().isGenerateResultSet(); } catch (SFException ex) { throw new SnowflakeSQLException(ex); } }
[ "public", "boolean", "getMoreResults", "(", "int", "current", ")", "throws", "SQLException", "{", "// clean up current result, if exists", "if", "(", "resultSet", "!=", "null", "&&", "(", "current", "==", "Statement", ".", "CLOSE_CURRENT_RESULT", "||", "current", "=...
Sets the result set to the next one, if available. @param current What to do with the current result. One of Statement.CLOSE_CURRENT_RESULT, Statement.CLOSE_ALL_RESULTS, or Statement.KEEP_CURRENT_RESULT @return true if there is a next result and it's a result set false if there are no more results, or there is a next result and it's an update count @throws SQLException if something fails while getting the next result
[ "Sets", "the", "result", "set", "to", "the", "next", "one", "if", "available", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/SFStatement.java#L877-L913
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/StorageProviderException.java
StorageProviderException.isServiceException404
public boolean isServiceException404() { if ((Exception) this instanceof AmazonServiceException) { AmazonServiceException asEx = (AmazonServiceException) ((java.lang.Exception) this); return (asEx.getStatusCode() == HttpStatus.SC_NOT_FOUND); } return false; }
java
public boolean isServiceException404() { if ((Exception) this instanceof AmazonServiceException) { AmazonServiceException asEx = (AmazonServiceException) ((java.lang.Exception) this); return (asEx.getStatusCode() == HttpStatus.SC_NOT_FOUND); } return false; }
[ "public", "boolean", "isServiceException404", "(", ")", "{", "if", "(", "(", "Exception", ")", "this", "instanceof", "AmazonServiceException", ")", "{", "AmazonServiceException", "asEx", "=", "(", "AmazonServiceException", ")", "(", "(", "java", ".", "lang", "."...
Returns true if this is an exception corresponding to a HTTP 404 error returned by the storage provider @return true if the specified exception is an AmazonServiceException instance and if it was thrown because of a 404, false otherwise.
[ "Returns", "true", "if", "this", "is", "an", "exception", "corresponding", "to", "a", "HTTP", "404", "error", "returned", "by", "the", "storage", "provider" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/StorageProviderException.java#L45-L54
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/IncidentUtil.java
IncidentUtil.oneLiner
public static String oneLiner(Throwable thrown) { StackTraceElement[] stack = thrown.getStackTrace(); String topOfStack = null; if (stack.length > 0) { topOfStack = " at " + stack[0]; } return thrown.toString() + topOfStack; }
java
public static String oneLiner(Throwable thrown) { StackTraceElement[] stack = thrown.getStackTrace(); String topOfStack = null; if (stack.length > 0) { topOfStack = " at " + stack[0]; } return thrown.toString() + topOfStack; }
[ "public", "static", "String", "oneLiner", "(", "Throwable", "thrown", ")", "{", "StackTraceElement", "[", "]", "stack", "=", "thrown", ".", "getStackTrace", "(", ")", ";", "String", "topOfStack", "=", "null", ";", "if", "(", "stack", ".", "length", ">", ...
Produce a one line description of the throwable, suitable for error message and log printing. @param thrown thrown object @return description of the thrown object
[ "Produce", "a", "one", "line", "description", "of", "the", "throwable", "suitable", "for", "error", "message", "and", "log", "printing", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/IncidentUtil.java#L54-L63
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/IncidentUtil.java
IncidentUtil.dumpVmMetrics
public static void dumpVmMetrics(String incidentId) { PrintWriter writer = null; try { String dumpFile = EventUtil.getDumpPathPrefix() + "/" + INC_DUMP_FILE_NAME + incidentId + INC_DUMP_FILE_EXT; final OutputStream outStream = new GZIPOutputStream(new FileOutputStream(dumpFile)); writer = new PrintWriter(outStream, true); final VirtualMachineMetrics vm = VirtualMachineMetrics.getInstance(); writer.print("\n\n\n--------------------------- METRICS " + "---------------------------\n\n"); writer.flush(); JsonFactory jf = new JsonFactory(); jf.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); ObjectMapper mapper = new ObjectMapper(jf); mapper.registerModule(new JodaModule()); mapper.setDateFormat(new ISO8601DateFormat()); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); MetricsServlet metrics = new MetricsServlet(Clock.defaultClock(), vm, Metrics.defaultRegistry(), jf, true); final JsonGenerator json = jf.createGenerator(outStream, JsonEncoding.UTF8); json.useDefaultPrettyPrinter(); json.writeStartObject(); // JVM metrics writeVmMetrics(json, vm); // Components metrics metrics.writeRegularMetrics(json, // json generator null, // class prefix false); // include full samples json.writeEndObject(); json.close(); logger.debug("Creating full thread dump in dump file {}", dumpFile); // Thread dump next.... writer.print("\n\n\n--------------------------- THREAD DUMP " + "---------------------------\n\n"); writer.flush(); vm.threadDump(outStream); logger.debug("Dump file {} is created.", dumpFile); } catch (Exception exc) { logger.error( "Unable to write dump file, exception: {}", exc.getMessage()); } finally { if (writer != null) { writer.close(); } } }
java
public static void dumpVmMetrics(String incidentId) { PrintWriter writer = null; try { String dumpFile = EventUtil.getDumpPathPrefix() + "/" + INC_DUMP_FILE_NAME + incidentId + INC_DUMP_FILE_EXT; final OutputStream outStream = new GZIPOutputStream(new FileOutputStream(dumpFile)); writer = new PrintWriter(outStream, true); final VirtualMachineMetrics vm = VirtualMachineMetrics.getInstance(); writer.print("\n\n\n--------------------------- METRICS " + "---------------------------\n\n"); writer.flush(); JsonFactory jf = new JsonFactory(); jf.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); ObjectMapper mapper = new ObjectMapper(jf); mapper.registerModule(new JodaModule()); mapper.setDateFormat(new ISO8601DateFormat()); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); MetricsServlet metrics = new MetricsServlet(Clock.defaultClock(), vm, Metrics.defaultRegistry(), jf, true); final JsonGenerator json = jf.createGenerator(outStream, JsonEncoding.UTF8); json.useDefaultPrettyPrinter(); json.writeStartObject(); // JVM metrics writeVmMetrics(json, vm); // Components metrics metrics.writeRegularMetrics(json, // json generator null, // class prefix false); // include full samples json.writeEndObject(); json.close(); logger.debug("Creating full thread dump in dump file {}", dumpFile); // Thread dump next.... writer.print("\n\n\n--------------------------- THREAD DUMP " + "---------------------------\n\n"); writer.flush(); vm.threadDump(outStream); logger.debug("Dump file {} is created.", dumpFile); } catch (Exception exc) { logger.error( "Unable to write dump file, exception: {}", exc.getMessage()); } finally { if (writer != null) { writer.close(); } } }
[ "public", "static", "void", "dumpVmMetrics", "(", "String", "incidentId", ")", "{", "PrintWriter", "writer", "=", "null", ";", "try", "{", "String", "dumpFile", "=", "EventUtil", ".", "getDumpPathPrefix", "(", ")", "+", "\"/\"", "+", "INC_DUMP_FILE_NAME", "+",...
Dumps JVM metrics for this process. @param incidentId incident id
[ "Dumps", "JVM", "metrics", "for", "this", "process", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/IncidentUtil.java#L83-L151
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/IncidentUtil.java
IncidentUtil.generateIncidentV2WithException
public static Throwable generateIncidentV2WithException(SFSession session, Throwable exc, String jobId, String requestId) { new Incident(session, exc, jobId, requestId).trigger(); return exc; }
java
public static Throwable generateIncidentV2WithException(SFSession session, Throwable exc, String jobId, String requestId) { new Incident(session, exc, jobId, requestId).trigger(); return exc; }
[ "public", "static", "Throwable", "generateIncidentV2WithException", "(", "SFSession", "session", ",", "Throwable", "exc", ",", "String", "jobId", ",", "String", "requestId", ")", "{", "new", "Incident", "(", "session", ",", "exc", ",", "jobId", ",", "requestId",...
Makes a V2 incident object and triggers ir, effectively reporting the given exception to GS and possibly to crashmanager @param session SFSession object to talk to GS through @param exc the Throwable we should report @param jobId jobId that failed @param requestId requestId that failed @return the given Throwable object
[ "Makes", "a", "V2", "incident", "object", "and", "triggers", "ir", "effectively", "reporting", "the", "given", "exception", "to", "GS", "and", "possibly", "to", "crashmanager" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/IncidentUtil.java#L279-L286
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/util/SFTimestamp.java
SFTimestamp.getUTCNow
public static String getUTCNow() { SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); //Time in GMT return dateFormatGmt.format(new Date()); }
java
public static String getUTCNow() { SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); //Time in GMT return dateFormatGmt.format(new Date()); }
[ "public", "static", "String", "getUTCNow", "(", ")", "{", "SimpleDateFormat", "dateFormatGmt", "=", "new", "SimpleDateFormat", "(", "\"yyyy-MM-dd HH:mm:ss\"", ")", ";", "dateFormatGmt", ".", "setTimeZone", "(", "TimeZone", ".", "getTimeZone", "(", "\"GMT\"", ")", ...
Get current time in UTC in the following format @return String representation in this format: yyyy-MM-dd HH:mm:ss
[ "Get", "current", "time", "in", "UTC", "in", "the", "following", "format" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/util/SFTimestamp.java#L17-L24
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java
SnowflakeAzureClient.renew
@Override public void renew(Map stageCredentials) throws SnowflakeSQLException { stageInfo.setCredentials(stageCredentials); setupAzureClient(stageInfo, encMat); }
java
@Override public void renew(Map stageCredentials) throws SnowflakeSQLException { stageInfo.setCredentials(stageCredentials); setupAzureClient(stageInfo, encMat); }
[ "@", "Override", "public", "void", "renew", "(", "Map", "stageCredentials", ")", "throws", "SnowflakeSQLException", "{", "stageInfo", ".", "setCredentials", "(", "stageCredentials", ")", ";", "setupAzureClient", "(", "stageInfo", ",", "encMat", ")", ";", "}" ]
Re-creates the encapsulated storage client with a fresh access token @param stageCredentials a Map (as returned by GS) which contains the new credential properties @throws SnowflakeSQLException failure to renew the client
[ "Re", "-", "creates", "the", "encapsulated", "storage", "client", "with", "a", "fresh", "access", "token" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java#L205-L210
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java
SnowflakeAzureClient.getObjectMetadata
@Override public StorageObjectMetadata getObjectMetadata(String remoteStorageLocation, String prefix) throws StorageProviderException { AzureObjectMetadata azureObjectMetadata = null; try { // Get a reference to the BLOB, to retrieve its metadata CloudBlobContainer container = azStorageClient.getContainerReference(remoteStorageLocation); CloudBlob blob = container.getBlockBlobReference(prefix); blob.downloadAttributes(); // Get the user-defined BLOB metadata Map<String, String> userDefinedMetadata = blob.getMetadata(); // Get the BLOB system properties we care about BlobProperties properties = blob.getProperties(); long contentLength = properties.getLength(); String contentEncoding = properties.getContentEncoding(); // Construct an Azure metadata object azureObjectMetadata = new AzureObjectMetadata(contentLength, contentEncoding, userDefinedMetadata); } catch (StorageException ex) { logger.debug("Failed to retrieve BLOB metadata: {} - {}", ex.getErrorCode(), ex.getExtendedErrorInformation()); throw new StorageProviderException(ex); } catch (URISyntaxException ex) { logger.debug("Cannot retrieve BLOB properties, invalid URI: {}", ex); throw new StorageProviderException(ex); } return azureObjectMetadata; }
java
@Override public StorageObjectMetadata getObjectMetadata(String remoteStorageLocation, String prefix) throws StorageProviderException { AzureObjectMetadata azureObjectMetadata = null; try { // Get a reference to the BLOB, to retrieve its metadata CloudBlobContainer container = azStorageClient.getContainerReference(remoteStorageLocation); CloudBlob blob = container.getBlockBlobReference(prefix); blob.downloadAttributes(); // Get the user-defined BLOB metadata Map<String, String> userDefinedMetadata = blob.getMetadata(); // Get the BLOB system properties we care about BlobProperties properties = blob.getProperties(); long contentLength = properties.getLength(); String contentEncoding = properties.getContentEncoding(); // Construct an Azure metadata object azureObjectMetadata = new AzureObjectMetadata(contentLength, contentEncoding, userDefinedMetadata); } catch (StorageException ex) { logger.debug("Failed to retrieve BLOB metadata: {} - {}", ex.getErrorCode(), ex.getExtendedErrorInformation()); throw new StorageProviderException(ex); } catch (URISyntaxException ex) { logger.debug("Cannot retrieve BLOB properties, invalid URI: {}", ex); throw new StorageProviderException(ex); } return azureObjectMetadata; }
[ "@", "Override", "public", "StorageObjectMetadata", "getObjectMetadata", "(", "String", "remoteStorageLocation", ",", "String", "prefix", ")", "throws", "StorageProviderException", "{", "AzureObjectMetadata", "azureObjectMetadata", "=", "null", ";", "try", "{", "// Get a ...
Returns the metadata properties for a remote storage object @param remoteStorageLocation location, i.e. bucket for S3 @param prefix the prefix/path of the object to retrieve @return storage metadata object @throws StorageProviderException azure storage exception
[ "Returns", "the", "metadata", "properties", "for", "a", "remote", "storage", "object" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java#L259-L295
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java
SnowflakeAzureClient.download
@Override public void download(SFSession connection, String command, String localLocation, String destFileName, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion) throws SnowflakeSQLException { int retryCount = 0; do { try { String localFilePath = localLocation + localFileSep + destFileName; File localFile = new File(localFilePath); CloudBlobContainer container = azStorageClient.getContainerReference(remoteStorageLocation); CloudBlob blob = container.getBlockBlobReference(stageFilePath); // Note that Azure doesn't offer a multi-part parallel download library, // where the user has control of block size and parallelism // we rely on Azure to handle the download, hence the "parallelism" parameter is ignored // in the Azure implementation of the method blob.downloadToFile(localFilePath); // Pull object metadata from Azure blob.downloadAttributes(); // Get the user-defined BLOB metadata Map<String, String> userDefinedMetadata = blob.getMetadata(); AbstractMap.SimpleEntry<String, String> encryptionData = parseEncryptionData(userDefinedMetadata.get(AZ_ENCRYPTIONDATAPROP)); String key = encryptionData.getKey(); String iv = encryptionData.getValue(); if (this.isEncrypting() && this.getEncryptionKeySize() <= 256) { if (key == null || iv == null) { throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "File metadata incomplete"); } // Decrypt file try { EncryptionProvider.decrypt(localFile, key, iv, this.encMat); } catch (Exception ex) { logger.error("Error decrypting file", ex); throw ex; } } return; } catch (Exception ex) { logger.debug("Download unsuccessful {}", ex); handleAzureException(ex, ++retryCount, "download", connection, command, this); } } while (retryCount <= getMaxRetries()); throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "Unexpected: download unsuccessful without exception!"); }
java
@Override public void download(SFSession connection, String command, String localLocation, String destFileName, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion) throws SnowflakeSQLException { int retryCount = 0; do { try { String localFilePath = localLocation + localFileSep + destFileName; File localFile = new File(localFilePath); CloudBlobContainer container = azStorageClient.getContainerReference(remoteStorageLocation); CloudBlob blob = container.getBlockBlobReference(stageFilePath); // Note that Azure doesn't offer a multi-part parallel download library, // where the user has control of block size and parallelism // we rely on Azure to handle the download, hence the "parallelism" parameter is ignored // in the Azure implementation of the method blob.downloadToFile(localFilePath); // Pull object metadata from Azure blob.downloadAttributes(); // Get the user-defined BLOB metadata Map<String, String> userDefinedMetadata = blob.getMetadata(); AbstractMap.SimpleEntry<String, String> encryptionData = parseEncryptionData(userDefinedMetadata.get(AZ_ENCRYPTIONDATAPROP)); String key = encryptionData.getKey(); String iv = encryptionData.getValue(); if (this.isEncrypting() && this.getEncryptionKeySize() <= 256) { if (key == null || iv == null) { throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "File metadata incomplete"); } // Decrypt file try { EncryptionProvider.decrypt(localFile, key, iv, this.encMat); } catch (Exception ex) { logger.error("Error decrypting file", ex); throw ex; } } return; } catch (Exception ex) { logger.debug("Download unsuccessful {}", ex); handleAzureException(ex, ++retryCount, "download", connection, command, this); } } while (retryCount <= getMaxRetries()); throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), "Unexpected: download unsuccessful without exception!"); }
[ "@", "Override", "public", "void", "download", "(", "SFSession", "connection", ",", "String", "command", ",", "String", "localLocation", ",", "String", "destFileName", ",", "int", "parallelism", ",", "String", "remoteStorageLocation", ",", "String", "stageFilePath",...
Download a file from remote storage. @param connection connection object @param command command to download file @param localLocation local file path @param destFileName destination file name @param parallelism [ not used by the Azure implementation ] @param remoteStorageLocation remote storage location, i.e. bucket for S3 @param stageFilePath stage file path @param stageRegion region name where the stage persists @throws SnowflakeSQLException download failure
[ "Download", "a", "file", "from", "remote", "storage", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java#L310-L376
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java
SnowflakeAzureClient.handleAzureException
private static void handleAzureException( Exception ex, int retryCount, String operation, SFSession connection, String command, SnowflakeAzureClient azClient) throws SnowflakeSQLException { // no need to retry if it is invalid key exception if (ex.getCause() instanceof InvalidKeyException) { // Most likely cause is that the unlimited strength policy files are not installed // Log the error and throw a message that explains the cause SnowflakeFileTransferAgent.throwJCEMissingError(operation, ex); } if (((StorageException) ex).getHttpStatusCode() == 403) { // A 403 indicates that the SAS token has expired, // we need to refresh the Azure client with the new token SnowflakeFileTransferAgent.renewExpiredToken(connection, command, azClient); } if (ex instanceof StorageException) { StorageException se = (StorageException) ex; // If we have exceeded the max number of retries, propagate the error if (retryCount > azClient.getMaxRetries()) { throw new SnowflakeSQLException(se, SqlState.SYSTEM_ERROR, ErrorCode.AZURE_SERVICE_ERROR.getMessageCode(), operation, se.getErrorCode(), se.getExtendedErrorInformation(), se.getHttpStatusCode(), se.getMessage()); } else { logger.debug("Encountered exception ({}) during {}, retry count: {}", ex.getMessage(), operation, retryCount); logger.debug("Stack trace: ", ex); // exponential backoff up to a limit int backoffInMillis = azClient.getRetryBackoffMin(); if (retryCount > 1) { backoffInMillis <<= (Math.min(retryCount - 1, azClient.getRetryBackoffMaxExponent())); } try { logger.debug("Sleep for {} milliseconds before retry", backoffInMillis); Thread.sleep(backoffInMillis); } catch (InterruptedException ex1) { // ignore } if (se.getHttpStatusCode() == 403) { // A 403 indicates that the SAS token has expired, // we need to refresh the Azure client with the new token SnowflakeFileTransferAgent.renewExpiredToken(connection, command, azClient); } } } else { if (ex instanceof InterruptedException || SnowflakeUtil.getRootCause(ex) instanceof SocketTimeoutException) { if (retryCount > azClient.getMaxRetries()) { throw new SnowflakeSQLException(ex, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), "Encountered exception during " + operation + ": " + ex.getMessage()); } else { logger.debug("Encountered exception ({}) during {}, retry count: {}", ex.getMessage(), operation, retryCount); } } else { throw new SnowflakeSQLException(ex, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), "Encountered exception during " + operation + ": " + ex.getMessage()); } } }
java
private static void handleAzureException( Exception ex, int retryCount, String operation, SFSession connection, String command, SnowflakeAzureClient azClient) throws SnowflakeSQLException { // no need to retry if it is invalid key exception if (ex.getCause() instanceof InvalidKeyException) { // Most likely cause is that the unlimited strength policy files are not installed // Log the error and throw a message that explains the cause SnowflakeFileTransferAgent.throwJCEMissingError(operation, ex); } if (((StorageException) ex).getHttpStatusCode() == 403) { // A 403 indicates that the SAS token has expired, // we need to refresh the Azure client with the new token SnowflakeFileTransferAgent.renewExpiredToken(connection, command, azClient); } if (ex instanceof StorageException) { StorageException se = (StorageException) ex; // If we have exceeded the max number of retries, propagate the error if (retryCount > azClient.getMaxRetries()) { throw new SnowflakeSQLException(se, SqlState.SYSTEM_ERROR, ErrorCode.AZURE_SERVICE_ERROR.getMessageCode(), operation, se.getErrorCode(), se.getExtendedErrorInformation(), se.getHttpStatusCode(), se.getMessage()); } else { logger.debug("Encountered exception ({}) during {}, retry count: {}", ex.getMessage(), operation, retryCount); logger.debug("Stack trace: ", ex); // exponential backoff up to a limit int backoffInMillis = azClient.getRetryBackoffMin(); if (retryCount > 1) { backoffInMillis <<= (Math.min(retryCount - 1, azClient.getRetryBackoffMaxExponent())); } try { logger.debug("Sleep for {} milliseconds before retry", backoffInMillis); Thread.sleep(backoffInMillis); } catch (InterruptedException ex1) { // ignore } if (se.getHttpStatusCode() == 403) { // A 403 indicates that the SAS token has expired, // we need to refresh the Azure client with the new token SnowflakeFileTransferAgent.renewExpiredToken(connection, command, azClient); } } } else { if (ex instanceof InterruptedException || SnowflakeUtil.getRootCause(ex) instanceof SocketTimeoutException) { if (retryCount > azClient.getMaxRetries()) { throw new SnowflakeSQLException(ex, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), "Encountered exception during " + operation + ": " + ex.getMessage()); } else { logger.debug("Encountered exception ({}) during {}, retry count: {}", ex.getMessage(), operation, retryCount); } } else { throw new SnowflakeSQLException(ex, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), "Encountered exception during " + operation + ": " + ex.getMessage()); } } }
[ "private", "static", "void", "handleAzureException", "(", "Exception", "ex", ",", "int", "retryCount", ",", "String", "operation", ",", "SFSession", "connection", ",", "String", "command", ",", "SnowflakeAzureClient", "azClient", ")", "throws", "SnowflakeSQLException"...
Handles exceptions thrown by Azure Storage It will retry transient errors as defined by the Azure Client retry policy It will re-create the client if the SAS token has expired, and re-try @param ex the exception to handle @param retryCount current number of retries, incremented by the caller before each call @param operation string that indicates the function/operation that was taking place, when the exception was raised, for example "upload" @param connection the current SFSession object used by the client @param command the command attempted at the time of the exception @param azClient the current Snowflake Azure client object @throws SnowflakeSQLException exceptions not handled
[ "Handles", "exceptions", "thrown", "by", "Azure", "Storage", "It", "will", "retry", "transient", "errors", "as", "defined", "by", "the", "Azure", "Client", "retry", "policy", "It", "will", "re", "-", "create", "the", "client", "if", "the", "SAS", "token", ...
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java#L662-L762
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java
SnowflakeAzureClient.addDigestMetadata
@Override public void addDigestMetadata(StorageObjectMetadata meta, String digest) { if (!SnowflakeUtil.isBlank(digest)) { // Azure doesn't allow hyphens in the name of a metadata field. meta.addUserMetadata("sfcdigest", digest); } }
java
@Override public void addDigestMetadata(StorageObjectMetadata meta, String digest) { if (!SnowflakeUtil.isBlank(digest)) { // Azure doesn't allow hyphens in the name of a metadata field. meta.addUserMetadata("sfcdigest", digest); } }
[ "@", "Override", "public", "void", "addDigestMetadata", "(", "StorageObjectMetadata", "meta", ",", "String", "digest", ")", "{", "if", "(", "!", "SnowflakeUtil", ".", "isBlank", "(", "digest", ")", ")", "{", "// Azure doesn't allow hyphens in the name of a metadata fi...
Adds digest metadata to the StorageObjectMetadata object
[ "Adds", "digest", "metadata", "to", "the", "StorageObjectMetadata", "object" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java#L857-L865
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.initMemoryLimit
private static long initMemoryLimit(final ResultOutput resultOutput) { // default setting long memoryLimit = SessionUtil.DEFAULT_CLIENT_MEMORY_LIMIT * 1024 * 1024; if (resultOutput.parameters.get(CLIENT_MEMORY_LIMIT) != null) { // use the settings from the customer memoryLimit = (int) resultOutput.parameters.get(CLIENT_MEMORY_LIMIT) * 1024L * 1024L; } long maxMemoryToUse = Runtime.getRuntime().maxMemory() * 8 / 10; if ((int) resultOutput.parameters.get(CLIENT_MEMORY_LIMIT) == SessionUtil.DEFAULT_CLIENT_MEMORY_LIMIT) { // if the memory limit is the default value and best effort memory is enabled // set the memory limit to 80% of the maximum as the best effort memoryLimit = Math.max(memoryLimit, maxMemoryToUse); } // always make sure memoryLimit <= 80% of the maximum memoryLimit = Math.min(memoryLimit, maxMemoryToUse); logger.debug("Set allowed memory usage to {} bytes", memoryLimit); return memoryLimit; }
java
private static long initMemoryLimit(final ResultOutput resultOutput) { // default setting long memoryLimit = SessionUtil.DEFAULT_CLIENT_MEMORY_LIMIT * 1024 * 1024; if (resultOutput.parameters.get(CLIENT_MEMORY_LIMIT) != null) { // use the settings from the customer memoryLimit = (int) resultOutput.parameters.get(CLIENT_MEMORY_LIMIT) * 1024L * 1024L; } long maxMemoryToUse = Runtime.getRuntime().maxMemory() * 8 / 10; if ((int) resultOutput.parameters.get(CLIENT_MEMORY_LIMIT) == SessionUtil.DEFAULT_CLIENT_MEMORY_LIMIT) { // if the memory limit is the default value and best effort memory is enabled // set the memory limit to 80% of the maximum as the best effort memoryLimit = Math.max(memoryLimit, maxMemoryToUse); } // always make sure memoryLimit <= 80% of the maximum memoryLimit = Math.min(memoryLimit, maxMemoryToUse); logger.debug("Set allowed memory usage to {} bytes", memoryLimit); return memoryLimit; }
[ "private", "static", "long", "initMemoryLimit", "(", "final", "ResultOutput", "resultOutput", ")", "{", "// default setting", "long", "memoryLimit", "=", "SessionUtil", ".", "DEFAULT_CLIENT_MEMORY_LIMIT", "*", "1024", "*", "1024", ";", "if", "(", "resultOutput", "."...
initialize memory limit in bytes @param resultOutput @return memory limit in bytes
[ "initialize", "memory", "limit", "in", "bytes" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L485-L510
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.effectiveParamValue
static private Object effectiveParamValue( Map<String, Object> parameters, String paramName) { String upper = paramName.toUpperCase(); Object value = parameters.get(upper); if (value != null) { return value; } value = defaultParameters.get(upper); if (value != null) { return value; } logger.debug("Unknown Common Parameter: {}", paramName); return null; }
java
static private Object effectiveParamValue( Map<String, Object> parameters, String paramName) { String upper = paramName.toUpperCase(); Object value = parameters.get(upper); if (value != null) { return value; } value = defaultParameters.get(upper); if (value != null) { return value; } logger.debug("Unknown Common Parameter: {}", paramName); return null; }
[ "static", "private", "Object", "effectiveParamValue", "(", "Map", "<", "String", ",", "Object", ">", "parameters", ",", "String", "paramName", ")", "{", "String", "upper", "=", "paramName", ".", "toUpperCase", "(", ")", ";", "Object", "value", "=", "paramete...
Returns the effective parameter value, using the value explicitly provided in parameters, or the default if absent @param parameters keyed in parameter name and valued in parameter value @param paramName Parameter to return the value of @return Effective value
[ "Returns", "the", "effective", "parameter", "value", "using", "the", "value", "explicitly", "provided", "in", "parameters", "or", "the", "default", "if", "absent" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L544-L564
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.specializedFormatter
static private SnowflakeDateTimeFormat specializedFormatter( Map<String, Object> parameters, String id, String param, String defaultFormat) { String sqlFormat = SnowflakeDateTimeFormat.effectiveSpecializedTimestampFormat( (String) effectiveParamValue(parameters, param), defaultFormat); SnowflakeDateTimeFormat formatter = new SnowflakeDateTimeFormat(sqlFormat); if (logger.isDebugEnabled()) { logger.debug("sql {} format: {}, java {} format: {}", id, sqlFormat, id, formatter.toSimpleDateTimePattern()); } return formatter; }
java
static private SnowflakeDateTimeFormat specializedFormatter( Map<String, Object> parameters, String id, String param, String defaultFormat) { String sqlFormat = SnowflakeDateTimeFormat.effectiveSpecializedTimestampFormat( (String) effectiveParamValue(parameters, param), defaultFormat); SnowflakeDateTimeFormat formatter = new SnowflakeDateTimeFormat(sqlFormat); if (logger.isDebugEnabled()) { logger.debug("sql {} format: {}, java {} format: {}", id, sqlFormat, id, formatter.toSimpleDateTimePattern()); } return formatter; }
[ "static", "private", "SnowflakeDateTimeFormat", "specializedFormatter", "(", "Map", "<", "String", ",", "Object", ">", "parameters", ",", "String", "id", ",", "String", "param", ",", "String", "defaultFormat", ")", "{", "String", "sqlFormat", "=", "SnowflakeDateTi...
Helper function building a formatter for a specialized timestamp type. Note that it will be based on either the 'param' value if set, or the default format provided.
[ "Helper", "function", "building", "a", "formatter", "for", "a", "specialized", "timestamp", "type", ".", "Note", "that", "it", "will", "be", "based", "on", "either", "the", "param", "value", "if", "set", "or", "the", "default", "format", "provided", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L571-L589
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.adjustTimestamp
static public Timestamp adjustTimestamp(Timestamp timestamp) { long milliToAdjust = ResultUtil.msDiffJulianToGregorian(timestamp); if (milliToAdjust != 0) { if (logger.isDebugEnabled()) { logger.debug("adjust timestamp by {} days", milliToAdjust / 86400000); } Timestamp newTimestamp = new Timestamp(timestamp.getTime() + milliToAdjust); newTimestamp.setNanos(timestamp.getNanos()); return newTimestamp; } else { return timestamp; } }
java
static public Timestamp adjustTimestamp(Timestamp timestamp) { long milliToAdjust = ResultUtil.msDiffJulianToGregorian(timestamp); if (milliToAdjust != 0) { if (logger.isDebugEnabled()) { logger.debug("adjust timestamp by {} days", milliToAdjust / 86400000); } Timestamp newTimestamp = new Timestamp(timestamp.getTime() + milliToAdjust); newTimestamp.setNanos(timestamp.getNanos()); return newTimestamp; } else { return timestamp; } }
[ "static", "public", "Timestamp", "adjustTimestamp", "(", "Timestamp", "timestamp", ")", "{", "long", "milliToAdjust", "=", "ResultUtil", ".", "msDiffJulianToGregorian", "(", "timestamp", ")", ";", "if", "(", "milliToAdjust", "!=", "0", ")", "{", "if", "(", "lo...
Adjust timestamp for dates before 1582-10-05 @param timestamp needs to be adjusted @return adjusted timestamp
[ "Adjust", "timestamp", "for", "dates", "before", "1582", "-", "10", "-", "05" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L597-L620
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.msDiffJulianToGregorian
static public long msDiffJulianToGregorian(java.util.Date date) { // get the year of the date Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); // if date is before 1582-10-05, apply the difference // by (H-(H/4)-2) where H is the hundreds digit of the year according to: // http://en.wikipedia.org/wiki/Gregorian_calendar if (date.getTime() < -12220156800000L) { // for dates on or before 02/28, use the previous year otherwise use // current year. // TODO: we need to revisit this since there is a potential issue using // the year/month/day from the calendar since that may not be the same // year/month/day as the original date (which is the problem we are // trying to solve here). if (month == 0 || (month == 1 && dayOfMonth <= 28)) { year = year - 1; } int hundreds = year / 100; int differenceInDays = hundreds - (hundreds / 4) - 2; return differenceInDays * 86400000; } else { return 0; } }
java
static public long msDiffJulianToGregorian(java.util.Date date) { // get the year of the date Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); // if date is before 1582-10-05, apply the difference // by (H-(H/4)-2) where H is the hundreds digit of the year according to: // http://en.wikipedia.org/wiki/Gregorian_calendar if (date.getTime() < -12220156800000L) { // for dates on or before 02/28, use the previous year otherwise use // current year. // TODO: we need to revisit this since there is a potential issue using // the year/month/day from the calendar since that may not be the same // year/month/day as the original date (which is the problem we are // trying to solve here). if (month == 0 || (month == 1 && dayOfMonth <= 28)) { year = year - 1; } int hundreds = year / 100; int differenceInDays = hundreds - (hundreds / 4) - 2; return differenceInDays * 86400000; } else { return 0; } }
[ "static", "public", "long", "msDiffJulianToGregorian", "(", "java", ".", "util", ".", "Date", "date", ")", "{", "// get the year of the date", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "cal", ".", "setTime", "(", "date", ")", ";"...
For dates before 1582-10-05, calculate the number of millis to adjust. @param date date before 1582-10-05 @return millis needs to be adjusted
[ "For", "dates", "before", "1582", "-", "10", "-", "05", "calculate", "the", "number", "of", "millis", "to", "adjust", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L628-L663
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getSFTimeAsString
static public String getSFTimeAsString( SFTime sft, int scale, SnowflakeDateTimeFormat timeFormatter) { return timeFormatter.format(sft, scale); }
java
static public String getSFTimeAsString( SFTime sft, int scale, SnowflakeDateTimeFormat timeFormatter) { return timeFormatter.format(sft, scale); }
[ "static", "public", "String", "getSFTimeAsString", "(", "SFTime", "sft", ",", "int", "scale", ",", "SnowflakeDateTimeFormat", "timeFormatter", ")", "{", "return", "timeFormatter", ".", "format", "(", "sft", ",", "scale", ")", ";", "}" ]
Convert a time value into a string @param sft snowflake time object @param scale time scale @param timeFormatter time formatter @return time in string
[ "Convert", "a", "time", "value", "into", "a", "string" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L764-L768
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getSFTimestampAsString
static public String getSFTimestampAsString( SFTimestamp sfTS, int columnType, int scale, SnowflakeDateTimeFormat timestampNTZFormatter, SnowflakeDateTimeFormat timestampLTZFormatter, SnowflakeDateTimeFormat timestampTZFormatter, SFSession session) throws SFException { // Derive the timestamp formatter to use SnowflakeDateTimeFormat formatter; if (columnType == Types.TIMESTAMP) { formatter = timestampNTZFormatter; } else if (columnType == SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_LTZ) { formatter = timestampLTZFormatter; } else // TZ { formatter = timestampTZFormatter; } if (formatter == null) { throw (SFException) IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.INTERNAL_ERROR, "missing timestamp formatter"), null, null); } try { Timestamp adjustedTimestamp = ResultUtil.adjustTimestamp(sfTS.getTimestamp()); return formatter.format( adjustedTimestamp, sfTS.getTimeZone(), scale); } catch (SFTimestamp.TimestampOperationNotAvailableException e) { // this timestamp doesn't fit into a Java timestamp, and therefore we // can't format it (for now). Just print it out as seconds since epoch. BigDecimal nanosSinceEpoch = sfTS.getNanosSinceEpoch(); BigDecimal secondsSinceEpoch = nanosSinceEpoch.scaleByPowerOfTen(-9); return secondsSinceEpoch.setScale(scale).toPlainString(); } }
java
static public String getSFTimestampAsString( SFTimestamp sfTS, int columnType, int scale, SnowflakeDateTimeFormat timestampNTZFormatter, SnowflakeDateTimeFormat timestampLTZFormatter, SnowflakeDateTimeFormat timestampTZFormatter, SFSession session) throws SFException { // Derive the timestamp formatter to use SnowflakeDateTimeFormat formatter; if (columnType == Types.TIMESTAMP) { formatter = timestampNTZFormatter; } else if (columnType == SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_LTZ) { formatter = timestampLTZFormatter; } else // TZ { formatter = timestampTZFormatter; } if (formatter == null) { throw (SFException) IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.INTERNAL_ERROR, "missing timestamp formatter"), null, null); } try { Timestamp adjustedTimestamp = ResultUtil.adjustTimestamp(sfTS.getTimestamp()); return formatter.format( adjustedTimestamp, sfTS.getTimeZone(), scale); } catch (SFTimestamp.TimestampOperationNotAvailableException e) { // this timestamp doesn't fit into a Java timestamp, and therefore we // can't format it (for now). Just print it out as seconds since epoch. BigDecimal nanosSinceEpoch = sfTS.getNanosSinceEpoch(); BigDecimal secondsSinceEpoch = nanosSinceEpoch.scaleByPowerOfTen(-9); return secondsSinceEpoch.setScale(scale).toPlainString(); } }
[ "static", "public", "String", "getSFTimestampAsString", "(", "SFTimestamp", "sfTS", ",", "int", "columnType", ",", "int", "scale", ",", "SnowflakeDateTimeFormat", "timestampNTZFormatter", ",", "SnowflakeDateTimeFormat", "timestampLTZFormatter", ",", "SnowflakeDateTimeFormat",...
Convert a SFTimestamp to a string value. @param sfTS snowflake timestamp object @param columnType internal snowflake t @param scale timestamp scale @param timestampNTZFormatter snowflake timestamp ntz format @param timestampLTZFormatter snowflake timestamp ltz format @param timestampTZFormatter snowflake timestamp tz format @param session session object @return timestamp in string in desired format @throws SFException timestamp format is missing
[ "Convert", "a", "SFTimestamp", "to", "a", "string", "value", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L794-L845
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getDateAsString
static public String getDateAsString( Date date, SnowflakeDateTimeFormat dateFormatter) { return dateFormatter.format(date, timeZoneUTC); }
java
static public String getDateAsString( Date date, SnowflakeDateTimeFormat dateFormatter) { return dateFormatter.format(date, timeZoneUTC); }
[ "static", "public", "String", "getDateAsString", "(", "Date", "date", ",", "SnowflakeDateTimeFormat", "dateFormatter", ")", "{", "return", "dateFormatter", ".", "format", "(", "date", ",", "timeZoneUTC", ")", ";", "}" ]
Convert a date value into a string @param date date will be converted @param dateFormatter date format @return date in string
[ "Convert", "a", "date", "value", "into", "a", "string" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L854-L858
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.adjustDate
static public Date adjustDate(Date date) { long milliToAdjust = ResultUtil.msDiffJulianToGregorian(date); if (milliToAdjust != 0) { // add the difference to the new date return new Date(date.getTime() + milliToAdjust); } else { return date; } }
java
static public Date adjustDate(Date date) { long milliToAdjust = ResultUtil.msDiffJulianToGregorian(date); if (milliToAdjust != 0) { // add the difference to the new date return new Date(date.getTime() + milliToAdjust); } else { return date; } }
[ "static", "public", "Date", "adjustDate", "(", "Date", "date", ")", "{", "long", "milliToAdjust", "=", "ResultUtil", ".", "msDiffJulianToGregorian", "(", "date", ")", ";", "if", "(", "milliToAdjust", "!=", "0", ")", "{", "// add the difference to the new date", ...
Adjust date for before 1582-10-05 @param date date before 1582-10-05 @return adjusted date
[ "Adjust", "date", "for", "before", "1582", "-", "10", "-", "05" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L866-L879
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getDate
static public Date getDate(String str, TimeZone tz, SFSession session) throws SFException { try { long milliSecsSinceEpoch = Long.valueOf(str) * 86400000; SFTimestamp tsInUTC = SFTimestamp.fromDate(new Date(milliSecsSinceEpoch), 0, TimeZone.getTimeZone("UTC")); SFTimestamp tsInClientTZ = tsInUTC.moveToTimeZone(tz); if (logger.isDebugEnabled()) { logger.debug("getDate: tz offset={}", tsInClientTZ.getTimeZone().getOffset(tsInClientTZ.getTime())); } // return the date adjusted to the JVM default time zone Date preDate = new Date(tsInClientTZ.getTime()); // if date is on or before 1582-10-04, apply the difference // by (H-H/4-2) where H is the hundreds digit of the year according to: // http://en.wikipedia.org/wiki/Gregorian_calendar Date newDate = adjustDate(preDate); if (logger.isDebugEnabled()) { logger.debug("Adjust date from {} to {}", preDate.toString(), newDate.toString()); } return newDate; } catch (NumberFormatException ex) { throw (SFException) IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.INTERNAL_ERROR, "Invalid date value: " + str), null, null); } }
java
static public Date getDate(String str, TimeZone tz, SFSession session) throws SFException { try { long milliSecsSinceEpoch = Long.valueOf(str) * 86400000; SFTimestamp tsInUTC = SFTimestamp.fromDate(new Date(milliSecsSinceEpoch), 0, TimeZone.getTimeZone("UTC")); SFTimestamp tsInClientTZ = tsInUTC.moveToTimeZone(tz); if (logger.isDebugEnabled()) { logger.debug("getDate: tz offset={}", tsInClientTZ.getTimeZone().getOffset(tsInClientTZ.getTime())); } // return the date adjusted to the JVM default time zone Date preDate = new Date(tsInClientTZ.getTime()); // if date is on or before 1582-10-04, apply the difference // by (H-H/4-2) where H is the hundreds digit of the year according to: // http://en.wikipedia.org/wiki/Gregorian_calendar Date newDate = adjustDate(preDate); if (logger.isDebugEnabled()) { logger.debug("Adjust date from {} to {}", preDate.toString(), newDate.toString()); } return newDate; } catch (NumberFormatException ex) { throw (SFException) IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.INTERNAL_ERROR, "Invalid date value: " + str), null, null); } }
[ "static", "public", "Date", "getDate", "(", "String", "str", ",", "TimeZone", "tz", ",", "SFSession", "session", ")", "throws", "SFException", "{", "try", "{", "long", "milliSecsSinceEpoch", "=", "Long", ".", "valueOf", "(", "str", ")", "*", "86400000", ";...
Convert a date internal object to a Date object in specified timezone. @param str snowflake date object @param tz timezone we want convert to @param session snowflake session object @return java date object @throws SFException if date is invalid
[ "Convert", "a", "date", "internal", "object", "to", "a", "Date", "object", "in", "specified", "timezone", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L890-L929
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.calculateUpdateCount
static public int calculateUpdateCount(SFBaseResultSet resultSet) throws SFException, SQLException { int updateCount = 0; SFStatementType statementType = resultSet.getStatementType(); if (statementType.isDML()) { while (resultSet.next()) { if (statementType == SFStatementType.COPY) { SFResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnIndex = resultSetMetaData.getColumnIndex("rows_loaded"); updateCount += columnIndex == -1 ? 0 : resultSet.getInt(columnIndex + 1); } else if (statementType == SFStatementType.INSERT || statementType == SFStatementType.UPDATE || statementType == SFStatementType.DELETE || statementType == SFStatementType.MERGE || statementType == SFStatementType.MULTI_INSERT) { int columnCount = resultSet.getMetaData().getColumnCount(); for (int i = 0; i < columnCount; i++) updateCount += resultSet.getLong(i + 1); // add up number of rows updated } else { updateCount = 0; } } } else { updateCount = statementType.isGenerateResultSet() ? -1 : 0; } return updateCount; }
java
static public int calculateUpdateCount(SFBaseResultSet resultSet) throws SFException, SQLException { int updateCount = 0; SFStatementType statementType = resultSet.getStatementType(); if (statementType.isDML()) { while (resultSet.next()) { if (statementType == SFStatementType.COPY) { SFResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnIndex = resultSetMetaData.getColumnIndex("rows_loaded"); updateCount += columnIndex == -1 ? 0 : resultSet.getInt(columnIndex + 1); } else if (statementType == SFStatementType.INSERT || statementType == SFStatementType.UPDATE || statementType == SFStatementType.DELETE || statementType == SFStatementType.MERGE || statementType == SFStatementType.MULTI_INSERT) { int columnCount = resultSet.getMetaData().getColumnCount(); for (int i = 0; i < columnCount; i++) updateCount += resultSet.getLong(i + 1); // add up number of rows updated } else { updateCount = 0; } } } else { updateCount = statementType.isGenerateResultSet() ? -1 : 0; } return updateCount; }
[ "static", "public", "int", "calculateUpdateCount", "(", "SFBaseResultSet", "resultSet", ")", "throws", "SFException", ",", "SQLException", "{", "int", "updateCount", "=", "0", ";", "SFStatementType", "statementType", "=", "resultSet", ".", "getStatementType", "(", "...
Calculate number of rows updated given a result set Interpret result format based on result set's statement type @param resultSet result set to extract update count from @return the number of rows updated @throws SFException if failed to calculate update count @throws SQLException if failed to calculate update count
[ "Calculate", "number", "of", "rows", "updated", "given", "a", "result", "set", "Interpret", "result", "format", "based", "on", "result", "set", "s", "statement", "type" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L952-L990
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.listSearchCaseInsensitive
public static int listSearchCaseInsensitive(List<String> source, String target) { for (int i = 0; i < source.size(); i++) { if (target.equalsIgnoreCase(source.get(i))) { return i; } } return -1; }
java
public static int listSearchCaseInsensitive(List<String> source, String target) { for (int i = 0; i < source.size(); i++) { if (target.equalsIgnoreCase(source.get(i))) { return i; } } return -1; }
[ "public", "static", "int", "listSearchCaseInsensitive", "(", "List", "<", "String", ">", "source", ",", "String", "target", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "source", ".", "size", "(", ")", ";", "i", "++", ")", "{", "if", ...
Given a list of String, do a case insensitive search for target string Used by resultsetMetadata to search for target column name @param source source string list @param target target string to match @return index in the source string list that matches the target string index starts from zero
[ "Given", "a", "list", "of", "String", "do", "a", "case", "insensitive", "search", "for", "target", "string", "Used", "by", "resultsetMetadata", "to", "search", "for", "target", "column", "name" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L1001-L1011
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getResultIds
private static List<String> getResultIds(JsonNode result) { JsonNode resultIds = result.path("data").path("resultIds"); if (resultIds.isNull() || resultIds.isMissingNode() || resultIds.asText().isEmpty()) { return Collections.emptyList(); } return new ArrayList<>(Arrays.asList(resultIds.asText().split(","))); }
java
private static List<String> getResultIds(JsonNode result) { JsonNode resultIds = result.path("data").path("resultIds"); if (resultIds.isNull() || resultIds.isMissingNode() || resultIds.asText().isEmpty()) { return Collections.emptyList(); } return new ArrayList<>(Arrays.asList(resultIds.asText().split(","))); }
[ "private", "static", "List", "<", "String", ">", "getResultIds", "(", "JsonNode", "result", ")", "{", "JsonNode", "resultIds", "=", "result", ".", "path", "(", "\"data\"", ")", ".", "path", "(", "\"resultIds\"", ")", ";", "if", "(", "resultIds", ".", "is...
Return the list of result IDs provided in a result, if available; otherwise return an empty list. @param result result json @return list of result IDs which can be used for result scans
[ "Return", "the", "list", "of", "result", "IDs", "provided", "in", "a", "result", "if", "available", ";", "otherwise", "return", "an", "empty", "list", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L1020-L1030
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getResultTypes
private static List<SFStatementType> getResultTypes(JsonNode result) { JsonNode resultTypes = result.path("data").path("resultTypes"); if (resultTypes.isNull() || resultTypes.isMissingNode() || resultTypes.asText().isEmpty()) { return Collections.emptyList(); } String[] typeStrs = resultTypes.asText().split(","); List<SFStatementType> res = new ArrayList<>(); for (String typeStr : typeStrs) { long typeId = Long.valueOf(typeStr); res.add(SFStatementType.lookUpTypeById(typeId)); } return res; }
java
private static List<SFStatementType> getResultTypes(JsonNode result) { JsonNode resultTypes = result.path("data").path("resultTypes"); if (resultTypes.isNull() || resultTypes.isMissingNode() || resultTypes.asText().isEmpty()) { return Collections.emptyList(); } String[] typeStrs = resultTypes.asText().split(","); List<SFStatementType> res = new ArrayList<>(); for (String typeStr : typeStrs) { long typeId = Long.valueOf(typeStr); res.add(SFStatementType.lookUpTypeById(typeId)); } return res; }
[ "private", "static", "List", "<", "SFStatementType", ">", "getResultTypes", "(", "JsonNode", "result", ")", "{", "JsonNode", "resultTypes", "=", "result", ".", "path", "(", "\"data\"", ")", ".", "path", "(", "\"resultTypes\"", ")", ";", "if", "(", "resultTyp...
Return the list of result types provided in a result, if available; otherwise return an empty list. @param result result json @return list of result IDs which can be used for result scans
[ "Return", "the", "list", "of", "result", "types", "provided", "in", "a", "result", "if", "available", ";", "otherwise", "return", "an", "empty", "list", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L1039-L1058
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/core/ResultUtil.java
ResultUtil.getChildResults
public static List<SFChildResult> getChildResults(SFSession session, String requestId, JsonNode result) throws SFException { List<String> ids = getResultIds(result); List<SFStatementType> types = getResultTypes(result); if (ids.size() != types.size()) { throw (SFException) IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.CHILD_RESULT_IDS_AND_TYPES_DIFFERENT_SIZES, ids.size(), types.size()), null, requestId); } List<SFChildResult> res = new ArrayList<>(); for (int i = 0; i < ids.size(); i++) { res.add(new SFChildResult(ids.get(i), types.get(i))); } return res; }
java
public static List<SFChildResult> getChildResults(SFSession session, String requestId, JsonNode result) throws SFException { List<String> ids = getResultIds(result); List<SFStatementType> types = getResultTypes(result); if (ids.size() != types.size()) { throw (SFException) IncidentUtil.generateIncidentV2WithException( session, new SFException(ErrorCode.CHILD_RESULT_IDS_AND_TYPES_DIFFERENT_SIZES, ids.size(), types.size()), null, requestId); } List<SFChildResult> res = new ArrayList<>(); for (int i = 0; i < ids.size(); i++) { res.add(new SFChildResult(ids.get(i), types.get(i))); } return res; }
[ "public", "static", "List", "<", "SFChildResult", ">", "getChildResults", "(", "SFSession", "session", ",", "String", "requestId", ",", "JsonNode", "result", ")", "throws", "SFException", "{", "List", "<", "String", ">", "ids", "=", "getResultIds", "(", "resul...
Return the list of child results provided in a result, if available; otherwise return an empty list @param session the current session @param requestId the current request id @param result result json @return list of child results @throws SFException if the number of child IDs does not match child statement types
[ "Return", "the", "list", "of", "child", "results", "provided", "in", "a", "result", "if", "available", ";", "otherwise", "return", "an", "empty", "list" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/core/ResultUtil.java#L1071-L1097
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/BufferStage.java
BufferStage.openFile
private synchronized void openFile() { try { String fName = _directory.getAbsolutePath() + File.separatorChar + StreamLoader.FILE_PREFIX + _stamp + _fileCount; if (_loader._compressDataBeforePut) { fName += StreamLoader.FILE_SUFFIX; } LOGGER.debug("openFile: {}", fName); OutputStream fileStream = new FileOutputStream(fName); if (_loader._compressDataBeforePut) { OutputStream gzipOutputStream = new GZIPOutputStream( fileStream, 64 * 1024, true) { { def.setLevel((int) _loader._compressLevel); } }; _outstream = new BufferedOutputStream(gzipOutputStream); } else { _outstream = new BufferedOutputStream(fileStream); } _file = new File(fName); _fileCount++; } catch (IOException ex) { _loader.abort(new Loader.ConnectionError(Utils.getCause(ex))); } }
java
private synchronized void openFile() { try { String fName = _directory.getAbsolutePath() + File.separatorChar + StreamLoader.FILE_PREFIX + _stamp + _fileCount; if (_loader._compressDataBeforePut) { fName += StreamLoader.FILE_SUFFIX; } LOGGER.debug("openFile: {}", fName); OutputStream fileStream = new FileOutputStream(fName); if (_loader._compressDataBeforePut) { OutputStream gzipOutputStream = new GZIPOutputStream( fileStream, 64 * 1024, true) { { def.setLevel((int) _loader._compressLevel); } }; _outstream = new BufferedOutputStream(gzipOutputStream); } else { _outstream = new BufferedOutputStream(fileStream); } _file = new File(fName); _fileCount++; } catch (IOException ex) { _loader.abort(new Loader.ConnectionError(Utils.getCause(ex))); } }
[ "private", "synchronized", "void", "openFile", "(", ")", "{", "try", "{", "String", "fName", "=", "_directory", ".", "getAbsolutePath", "(", ")", "+", "File", ".", "separatorChar", "+", "StreamLoader", ".", "FILE_PREFIX", "+", "_stamp", "+", "_fileCount", ";...
Create local file for caching data before upload
[ "Create", "local", "file", "for", "caching", "data", "before", "upload" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/BufferStage.java#L147-L185
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/BufferStage.java
BufferStage.stageData
boolean stageData(final byte[] line) throws IOException { if (this._rowCount % 10000 == 0) { LOGGER.debug( "rowCount: {}, currentSize: {}", this._rowCount, _currentSize); } _outstream.write(line); _currentSize += line.length; _outstream.write(newLineBytes); this._rowCount++; if (_loader._testRemoteBadCSV) { // inject garbage for a negative test case // The file will be uploaded to the stage, but COPY command will // fail and raise LoaderError _outstream.write(new byte[]{(byte) 0x01, (byte) 0x02}); _outstream.write(newLineBytes); this._rowCount++; } if (_currentSize >= this._csvFileSize) { LOGGER.debug("name: {}, currentSize: {}, Threshold: {}," + " fileCount: {}, fileBucketSize: {}", _file.getAbsolutePath(), _currentSize, this._csvFileSize, _fileCount, this._csvFileBucketSize); _outstream.flush(); _outstream.close(); _outstream = null; FileUploader fu = new FileUploader(_loader, _location, _file); fu.upload(); _uploaders.add(fu); openFile(); _currentSize = 0; } return _fileCount > this._csvFileBucketSize; }
java
boolean stageData(final byte[] line) throws IOException { if (this._rowCount % 10000 == 0) { LOGGER.debug( "rowCount: {}, currentSize: {}", this._rowCount, _currentSize); } _outstream.write(line); _currentSize += line.length; _outstream.write(newLineBytes); this._rowCount++; if (_loader._testRemoteBadCSV) { // inject garbage for a negative test case // The file will be uploaded to the stage, but COPY command will // fail and raise LoaderError _outstream.write(new byte[]{(byte) 0x01, (byte) 0x02}); _outstream.write(newLineBytes); this._rowCount++; } if (_currentSize >= this._csvFileSize) { LOGGER.debug("name: {}, currentSize: {}, Threshold: {}," + " fileCount: {}, fileBucketSize: {}", _file.getAbsolutePath(), _currentSize, this._csvFileSize, _fileCount, this._csvFileBucketSize); _outstream.flush(); _outstream.close(); _outstream = null; FileUploader fu = new FileUploader(_loader, _location, _file); fu.upload(); _uploaders.add(fu); openFile(); _currentSize = 0; } return _fileCount > this._csvFileBucketSize; }
[ "boolean", "stageData", "(", "final", "byte", "[", "]", "line", ")", "throws", "IOException", "{", "if", "(", "this", ".", "_rowCount", "%", "10000", "==", "0", ")", "{", "LOGGER", ".", "debug", "(", "\"rowCount: {}, currentSize: {}\"", ",", "this", ".", ...
not thread safe
[ "not", "thread", "safe" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/BufferStage.java#L191-L231
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/BufferStage.java
BufferStage.completeUploading
void completeUploading() throws IOException { LOGGER.debug("name: {}, currentSize: {}, Threshold: {}," + " fileCount: {}, fileBucketSize: {}", _file.getAbsolutePath(), _currentSize, this._csvFileSize, _fileCount, this._csvFileBucketSize); _outstream.flush(); _outstream.close(); //last file if (_currentSize > 0) { FileUploader fu = new FileUploader(_loader, _location, _file); fu.upload(); _uploaders.add(fu); } else { // delete empty file _file.delete(); } for (FileUploader fu : _uploaders) { // Finish all files being uploaded fu.join(); } // Delete the directory once we are done (for easier tracking // of what is going on) _directory.deleteOnExit(); if (this._rowCount == 0) { setState(State.EMPTY); } }
java
void completeUploading() throws IOException { LOGGER.debug("name: {}, currentSize: {}, Threshold: {}," + " fileCount: {}, fileBucketSize: {}", _file.getAbsolutePath(), _currentSize, this._csvFileSize, _fileCount, this._csvFileBucketSize); _outstream.flush(); _outstream.close(); //last file if (_currentSize > 0) { FileUploader fu = new FileUploader(_loader, _location, _file); fu.upload(); _uploaders.add(fu); } else { // delete empty file _file.delete(); } for (FileUploader fu : _uploaders) { // Finish all files being uploaded fu.join(); } // Delete the directory once we are done (for easier tracking // of what is going on) _directory.deleteOnExit(); if (this._rowCount == 0) { setState(State.EMPTY); } }
[ "void", "completeUploading", "(", ")", "throws", "IOException", "{", "LOGGER", ".", "debug", "(", "\"name: {}, currentSize: {}, Threshold: {},\"", "+", "\" fileCount: {}, fileBucketSize: {}\"", ",", "_file", ".", "getAbsolutePath", "(", ")", ",", "_currentSize", ",", "t...
Wait for all files to finish uploading and schedule stage for processing @throws IOException raises an exception if IO error occurs
[ "Wait", "for", "all", "files", "to", "finish", "uploading", "and", "schedule", "stage", "for", "processing" ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/BufferStage.java#L239-L276
train
snowflakedb/snowflake-jdbc
src/main/java/net/snowflake/client/loader/BufferStage.java
BufferStage.escapeFileSeparatorChar
private static String escapeFileSeparatorChar(String fname) { if (File.separatorChar == '\\') { return fname.replaceAll(File.separator + File.separator, "_"); } else { return fname.replaceAll(File.separator, "_"); } }
java
private static String escapeFileSeparatorChar(String fname) { if (File.separatorChar == '\\') { return fname.replaceAll(File.separator + File.separator, "_"); } else { return fname.replaceAll(File.separator, "_"); } }
[ "private", "static", "String", "escapeFileSeparatorChar", "(", "String", "fname", ")", "{", "if", "(", "File", ".", "separatorChar", "==", "'", "'", ")", "{", "return", "fname", ".", "replaceAll", "(", "File", ".", "separator", "+", "File", ".", "separator...
Escape file separator char to underscore. This prevents the file name from using file path separator. @param fname @return escaped file name
[ "Escape", "file", "separator", "char", "to", "underscore", ".", "This", "prevents", "the", "file", "name", "from", "using", "file", "path", "separator", "." ]
98567b5a57753f29d51446809640b969a099658f
https://github.com/snowflakedb/snowflake-jdbc/blob/98567b5a57753f29d51446809640b969a099658f/src/main/java/net/snowflake/client/loader/BufferStage.java#L349-L359
train
bmwcarit/joynr
java/core/libjoynr/src/main/java/io/joynr/proxy/ProxyInvocationHandlerImpl.java
ProxyInvocationHandlerImpl.executeSyncMethod
@CheckForNull private Object executeSyncMethod(Method method, Object[] args) throws ApplicationException { if (preparingForShutdown.get()) { throw new JoynrIllegalStateException("Preparing for shutdown. Only stateless methods can be called."); } return executeMethodWithCaller(method, args, new ConnectorCaller() { @Override public Object call(Method method, Object[] args) throws ApplicationException { return connector.executeSyncMethod(method, args); } }); }
java
@CheckForNull private Object executeSyncMethod(Method method, Object[] args) throws ApplicationException { if (preparingForShutdown.get()) { throw new JoynrIllegalStateException("Preparing for shutdown. Only stateless methods can be called."); } return executeMethodWithCaller(method, args, new ConnectorCaller() { @Override public Object call(Method method, Object[] args) throws ApplicationException { return connector.executeSyncMethod(method, args); } }); }
[ "@", "CheckForNull", "private", "Object", "executeSyncMethod", "(", "Method", "method", ",", "Object", "[", "]", "args", ")", "throws", "ApplicationException", "{", "if", "(", "preparingForShutdown", ".", "get", "(", ")", ")", "{", "throw", "new", "JoynrIllega...
executeSyncMethod is called whenever a method of the synchronous interface which is provided by the proxy is called. The ProxyInvocationHandler will check the arbitration status before the call is delegated to the connector. If the arbitration is still in progress the synchronous call will block until the arbitration was successful or the timeout elapsed. @throws ApplicationException @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
[ "executeSyncMethod", "is", "called", "whenever", "a", "method", "of", "the", "synchronous", "interface", "which", "is", "provided", "by", "the", "proxy", "is", "called", ".", "The", "ProxyInvocationHandler", "will", "check", "the", "arbitration", "status", "before...
b7a92bad1cf2f093de080facd2c803560f4c6c26
https://github.com/bmwcarit/joynr/blob/b7a92bad1cf2f093de080facd2c803560f4c6c26/java/core/libjoynr/src/main/java/io/joynr/proxy/ProxyInvocationHandlerImpl.java#L143-L154
train