Skip to content

Conversation

@yangshangqing95
Copy link
Member

@yangshangqing95 yangshangqing95 commented Oct 29, 2025

Description

This PR adds support for configuring additional Druid connector properties, specifically timeout and timezone.
The motivation is to provide client-side safeguards: poorly written SQL queries can trigger full table scans in Druid, putting significant pressure on the Druid cluster. By allowing these properties to be set on the client side, we can limit query execution time and control time zone interpretation, mitigating potential cluster impact.

Additional context and related issues

druid.execution-timeout allows users to limit the maximum execution time of a query.
druid.sql-timezone sets the time zone for interpreting timestamp values in SQL queries.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## Section
* Support for set Druid connection properties.

Summary by Sourcery

Add client-side configuration properties for the Druid connector to control query timeout and SQL timezone interpretation.

New Features:

  • Add druid.execution-timeout property to limit query execution time on the client side
  • Add druid.sql-timezone property to configure the time zone for SQL queries

Enhancements:

  • Bind DruidConfig via Airlift ConfigBinder and apply its properties when creating the Druid JDBC connection

Build:

  • Add Airlift configuration and configuration-testing dependencies to the Druid plugin POM

Documentation:

  • Update Druid connector documentation with descriptions and defaults for the new configuration properties

Tests:

  • Add TestDruidConfig to verify default values and explicit mappings of the new properties

@cla-bot cla-bot bot added the cla-signed label Oct 29, 2025
@github-actions github-actions bot added docs druid Druid connector labels Oct 29, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 29, 2025

Reviewer's Guide

This PR adds client-side support for configuring Druid query timeout and SQL timezone by introducing a new DruidConfig class bound via Airlift’s ConfigBinder, wiring it into the JDBC client to populate connection properties, adding corresponding unit tests, updating build dependencies, and extending the documentation.

Entity relationship diagram for new Druid connector properties

erDiagram
    DRUID_CONFIG {
        long executionTimeout
        string sqlTimezone
    }
    DRUID_JDBC_CLIENT_MODULE {
        Properties connectionProperties
    }
    DRUID_CONFIG ||--o{ DRUID_JDBC_CLIENT_MODULE : provides
Loading

Class diagram for new DruidConfig and its integration

classDiagram
class DruidConfig {
  - long executionTimeout
  - String sqlTimezone
  + setExecutionTimeout(long): DruidConfig
  + getExecutionTimeout(): long
  + setSqlTimezone(String): DruidConfig
  + getSqlTimezone(): String
}
class DruidJdbcClientModule {
  + configure(Binder): void
  + createConnectionFactory(BaseJdbcConfig, CredentialProvider, DruidConfig, OpenTelemetry): ConnectionFactory
  - getConnectionProperties(DruidConfig): Properties
}
DruidJdbcClientModule --> DruidConfig: uses
Loading

File-Level Changes

Change Details Files
Define and validate DruidConfig for execution timeout and timezone
  • Add DruidConfig class with @config annotations and getters
  • Implement TestDruidConfig covering default and explicit mappings
plugin/trino-druid/src/main/java/io/trino/plugin/druid/DruidConfig.java
plugin/trino-druid/src/test/java/io/trino/plugin/druid/TestDruidConfig.java
Bind DruidConfig and propagate properties in JDBC client
  • Register DruidConfig via configBinder
  • Inject DruidConfig into createConnectionFactory
  • Implement getConnectionProperties to set timeout and sqlTimeZone on DriverConnectionFactory
plugin/trino-druid/src/main/java/io/trino/plugin/druid/DruidJdbcClientModule.java
Add Airlift configuration dependencies for runtime and testing
  • Include io.airlift:configuration for config binding
  • Include io.airlift:configuration-testing for unit tests
plugin/trino-druid/pom.xml
Document new Druid connector properties in docs
  • Extend druid.md with a table for druid.execution-timeout and druid.sql-timezone
  • Describe default values and behaviors
docs/src/main/sphinx/connector/druid.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `plugin/trino-druid/src/test/java/io/trino/plugin/druid/TestDruidConfig.java:27-28` </location>
<code_context>
+
+class TestDruidConfig
+{
+    @Test
+    void testDefaults()
+    {
+        assertRecordedDefaults(recordDefaults(DruidConfig.class)
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for invalid or edge-case property values.

Tests currently only cover valid property mappings. Please add cases for negative executionTimeout, very large values, and invalid time zone strings to verify robust handling of edge scenarios.

Suggested implementation:

```java
    @Test
    void testExplicitPropertyMappings()
    {
        Map<String, String> properties = ImmutableMap.<String, String>builder()
                .put("druid.execution-timeout", "10000")
                .put("druid.sql-timezone", "UTC")

    }

    @Test
    void testInvalidAndEdgeCasePropertyValues()
    {
        // Negative executionTimeout
        Map<String, String> negativeTimeout = ImmutableMap.of(
                "druid.execution-timeout", "-1"
        );
        try {
            DruidConfig config = new DruidConfig();
            assertFullMapping(negativeTimeout, config.setExecutionTimeout(-1));
        } catch (Exception e) {
            // Expected: negative timeout may throw or be handled
        }

        // Very large executionTimeout
        Map<String, String> largeTimeout = ImmutableMap.of(
                "druid.execution-timeout", String.valueOf(Long.MAX_VALUE)
        );
        DruidConfig largeConfig = new DruidConfig().setExecutionTimeout(Long.MAX_VALUE);
        assertFullMapping(largeTimeout, largeConfig);

        // Invalid sqlTimezone string
        Map<String, String> invalidTimezone = ImmutableMap.of(
                "druid.sql-timezone", "NotARealTimezone"
        );
        try {
            DruidConfig config = new DruidConfig();
            assertFullMapping(invalidTimezone, config.setSqlTimezone("NotARealTimezone"));
        } catch (Exception e) {
            // Expected: invalid timezone may throw or be handled
        }
    }

```

- If `DruidConfig` does not throw exceptions for invalid values, you may want to add assertions to check for defaulting or error states.
- Ensure that `ImmutableMap` is imported if not already present.
- Adjust exception handling and assertions to match the actual behavior of `DruidConfig` for invalid values.
</issue_to_address>

### Comment 2
<location> `docs/src/main/sphinx/connector/druid.md:48` </location>
<code_context>
 connection-password=secret
 ```

+Additionally, following configuration properties can be set depending on the use-case:
+
+:::{list-table} Druid configuration properties
</code_context>

<issue_to_address>
**issue (typo):** Missing article: should be 'the following configuration properties'.

Please update the sentence as suggested for grammatical accuracy.

```suggestion
Additionally, the following configuration properties can be set depending on the use-case:
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

connection-password=secret
```

Additionally, following configuration properties can be set depending on the use-case:
Copy link

Choose a reason for hiding this comment

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

issue (typo): Missing article: should be 'the following configuration properties'.

Please update the sentence as suggested for grammatical accuracy.

Suggested change
Additionally, following configuration properties can be set depending on the use-case:
Additionally, the following configuration properties can be set depending on the use-case:


public class DruidConfig
{
private long executionTimeout; // milliseconds
Copy link
Member

Choose a reason for hiding this comment

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

Use airlift duration class.

Copy link
Member Author

Choose a reason for hiding this comment

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

done


public class DruidConfig
{
private Duration executionTimeout; // milliseconds
Copy link
Member

Choose a reason for hiding this comment

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

Remove the obsolete code comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;
import static java.util.concurrent.TimeUnit.SECONDS;

class TestDruidConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

final

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@yangshangqing95
Copy link
Member Author

Hi @chenjian2664 @ebyhr, is this good to be merged? thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants