Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
### Updated
- Added validation for positive integer configuration properties (RowsFetchedPerBlock, BatchInsertSize, etc.) to prevent hangs and errors when set to zero or negative values.
- Updated Circuit breaker to be triggered by 429 errors too.
- Log timestamps now explicitly display timezone.

### Fixed

- Fix driver crash when using `INTERVAL` types.
- Fix connection failure in restricted environments when `LogLevel.OFF` is used.
- Fix U2M by including SDK OAuth HTML callback resources.
- Remove global JVM timezone modification from `Driver.main()` to prevent side effects on other code running in the same JVM.

---
*Note: When making changes, please add your change under the appropriate section with a brief description.*
3 changes: 0 additions & 3 deletions src/main/java/com/databricks/client/jdbc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;

Expand All @@ -39,8 +38,6 @@ public class Driver implements IDatabricksDriver {
}

public static void main(String[] args) {
TimeZone.setDefault(
TimeZone.getTimeZone("UTC")); // Logging, timestamps are in UTC across the application
System.out.printf("The driver {%s} has been initialized.%n", Driver.class);
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/databricks/jdbc/log/Slf4jFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

Expand All @@ -12,13 +11,12 @@
*/
public class Slf4jFormatter extends Formatter {

private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss z";

private static final SimpleDateFormat dateFormat;

static {
dateFormat = new SimpleDateFormat(DATE_FORMAT);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to make this threadsafe?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this should not be used across threads. Or you can use DateTimeFormatter which is thread safe

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! this is the existing implementation that this PR does not touch. But makes sense to change that too. Addressed ✅

dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}

/** {@inheritDoc} */
Expand Down
17 changes: 11 additions & 6 deletions src/test/java/com/databricks/jdbc/log/Slf4jFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,29 @@ public void setUp() {

@Test
public void testFormat() {
// Create a sample LogRecord
LogRecord record = new LogRecord(Level.INFO, "Test message");
record.setSourceClassName("TestClass");
record.setSourceMethodName("testMethod");

// Set a specific timestamp for testing
Instant instant = Instant.parse("2021-07-01T00:00:00Z");
record.setInstant(instant);

// Format the log record
String formattedLog = formatter.format(record);

// Expected format: "yyyy-MM-dd HH:mm:ss LEVEL ClassName#methodName - message"
// Use system default timezone (matches formatter)
TimeZone formatterZone = TimeZone.getDefault();

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
dateFormat.setTimeZone(formatterZone);

String expectedTimestamp = dateFormat.format(Date.from(instant));

// Use SHORT display name instead of ID (Asia/Kolkata → IST)
String expectedZone = formatterZone.getDisplayName(false, TimeZone.SHORT);

String expected =
String.format("%s INFO TestClass#testMethod - Test message%n", expectedTimestamp);
String.format(
"%s %s INFO TestClass#testMethod - Test message%n", expectedTimestamp, expectedZone);

assertEquals(expected, formattedLog);
}
Expand Down
Loading