Skip to content

Commit 8ecada0

Browse files
committed
fix
1 parent 1614354 commit 8ecada0

5 files changed

Lines changed: 41 additions & 20 deletions

File tree

databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperties.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public final class ConnectionProperties {
3535
public static final ConnectionProperty<Integer> QUERY_TIMEOUT = new QueryTimeout();
3636
public static final ConnectionProperty<Integer> SOCKET_TIMEOUT = new SocketTimeout();
3737

38-
public static final ConnectionProperty<String> PRESIGNED_URL_DISABLED = new PresignedUrlDisabled();
38+
public static final ConnectionProperty<Boolean> PRESIGNED_URL_DISABLED = new PresignedUrlDisabled();
39+
public static final ConnectionProperty<String> PRESIGN = new Presign();
3940
public static final ConnectionProperty<Boolean> COPY_PURGE = new CopyPurge();
4041
public static final ConnectionProperty<String> NULL_DISPLAY = new NullDisplay();
4142
public static final ConnectionProperty<String> BINARY_FORMAT = new BinaryFormat();
@@ -59,6 +60,7 @@ public final class ConnectionProperties {
5960
.add(DATABASE)
6061
.add(ACCESS_TOKEN)
6162
.add(PRESIGNED_URL_DISABLED)
63+
.add(PRESIGN)
6264
.add(QUERY_TIMEOUT)
6365
.add(CONNECTION_TIMEOUT)
6466
.add(SOCKET_TIMEOUT)
@@ -188,9 +190,16 @@ public AccessToken() {
188190
}
189191

190192
private static class PresignedUrlDisabled
191-
extends AbstractConnectionProperty<String> {
193+
extends AbstractConnectionProperty<Boolean> {
192194
public PresignedUrlDisabled() {
193-
super("presigned_url_disabled", Optional.of("auto"), NOT_REQUIRED, ALLOWED, STRING_CONVERTER);
195+
super("presigned_url_disabled", Optional.of("false"), NOT_REQUIRED, ALLOWED, BOOLEAN_CONVERTER);
196+
}
197+
}
198+
199+
private static class Presign
200+
extends AbstractConnectionProperty<String> {
201+
public Presign() {
202+
super("presign", NOT_REQUIRED, ALLOWED, STRING_CONVERTER);
194203
}
195204
}
196205

databend-jdbc/src/main/java/com/databend/jdbc/DatabendConnection.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ private void login() throws SQLException {
175175
}
176176

177177
private void checkPresign() {
178-
String mode = this.driverUri.presignedUrlDisabled();
179-
switch (mode.toLowerCase(Locale.US)) {
178+
String presign = this.driverUri.getPresign();
179+
if (presign == null || presign.isEmpty()) {
180+
// fallback to legacy presigned_url_disabled boolean
181+
this.presignDisabled = this.driverUri.presignedUrlDisabled();
182+
return;
183+
}
184+
switch (presign.toLowerCase(Locale.US)) {
180185
case "auto":
181186
String host = this.httpUri.getHost();
182187
if (host != null && (host.endsWith(".databend.com")
@@ -192,23 +197,23 @@ private void checkPresign() {
192197
PresignContext.newPresignContext(this, PresignContext.PresignMethod.UPLOAD, "~", ".databend-jdbc/check");
193198
this.presignDisabled = false;
194199
} catch (Exception e) {
195-
logger.warning("presign mode off with error detected: " + e.getMessage());
200+
logger.warning("presign off: detect failed: " + e.getMessage());
196201
this.presignDisabled = true;
197202
}
198203
break;
199-
case "true":
200-
this.presignDisabled = true;
201-
break;
202-
case "false":
204+
case "on":
203205
this.presignDisabled = false;
204206
break;
205-
default:
206-
logger.warning("Unknown presigned_url_disabled value: " + mode + ", defaulting to auto");
207+
case "off":
207208
this.presignDisabled = true;
208209
break;
210+
default:
211+
logger.warning("Unknown presign value: " + presign + ", falling back to presigned_url_disabled");
212+
this.presignDisabled = this.driverUri.presignedUrlDisabled();
213+
break;
209214
}
210215
if (this.debug()) {
211-
logger.info("presign disabled: " + this.presignDisabled + " (mode=" + mode + ", host=" + this.httpUri.getHost() + ")");
216+
logger.info("presign disabled: " + this.presignDisabled + " (presign=" + presign + ", host=" + this.httpUri.getHost() + ")");
212217
}
213218
}
214219

databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriverUri.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ final class DatabendDriverUri {
5353
private final String nullDisplay;
5454
private final String binaryFormat;
5555
private final String database;
56-
private final String presignedUrlDisabled;
56+
private final boolean presignedUrlDisabled;
57+
private final String presign;
5758
private final Integer connectionTimeout;
5859
private final Integer queryTimeout;
5960
private final Integer socketTimeout;
@@ -79,7 +80,8 @@ private DatabendDriverUri(String url, Properties driverProperties)
7980
this.tenant = TENANT.getValue(properties).orElse("");
8081
this.uri = canonicalizeUri(rawUri, this.useSecureConnection, this.sslmode);
8182
this.database = DATABASE.getValue(properties).orElse("default");
82-
this.presignedUrlDisabled = PRESIGNED_URL_DISABLED.getValue(properties).orElse("auto");
83+
this.presignedUrlDisabled = PRESIGNED_URL_DISABLED.getRequiredValue(properties);
84+
this.presign = PRESIGN.getValue(properties).orElse("");
8385
this.copyPurge = COPY_PURGE.getValue(properties).orElse(true);
8486
this.nullDisplay = NULL_DISPLAY.getValue(properties).orElse("\\N");
8587
this.binaryFormat = BINARY_FORMAT.getValue(properties).orElse("");
@@ -305,10 +307,14 @@ public String getDatabase() {
305307
return database;
306308
}
307309

308-
public String presignedUrlDisabled() {
310+
public Boolean presignedUrlDisabled() {
309311
return presignedUrlDisabled;
310312
}
311313

314+
public String getPresign() {
315+
return presign;
316+
}
317+
312318
public Boolean copyPurge() {
313319
return copyPurge;
314320
}

databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDriverUri.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void testUserDatabaseProp() throws SQLException {
149149
Assert.assertEquals(uri.getWaitTimeSecs().intValue(), PaginationOptions.getDefaultWaitTimeSec());
150150
Assert.assertEquals(uri.getMaxRowsInBuffer().intValue(), PaginationOptions.getDefaultMaxRowsInBuffer());
151151
Assert.assertEquals(uri.getMaxRowsPerPage().intValue(), PaginationOptions.getDefaultMaxRowsPerPage());
152-
Assert.assertEquals("auto", uri.presignedUrlDisabled());
152+
Assert.assertFalse(uri.presignedUrlDisabled().booleanValue());
153153
Assert.assertTrue(uri.copyPurge().booleanValue());
154154
Assert.assertEquals("\\N", uri.nullDisplay());
155155
Assert.assertEquals("base64", uri.binaryFormat());
@@ -175,7 +175,7 @@ public void testUserDatabasePropFull() throws SQLException {
175175
Assert.assertEquals(uri.getWaitTimeSecs().intValue(), 1);
176176
Assert.assertEquals(uri.getMaxRowsInBuffer().intValue(), 10);
177177
Assert.assertEquals(uri.getMaxRowsPerPage().intValue(), 5);
178-
Assert.assertEquals("true", uri.presignedUrlDisabled());
178+
Assert.assertTrue(uri.presignedUrlDisabled().booleanValue());
179179
Assert.assertTrue(uri.copyPurge().booleanValue());
180180
Assert.assertEquals("", uri.binaryFormat().toString());
181181
}
@@ -209,7 +209,7 @@ public void testFull() throws SQLException {
209209
Assert.assertEquals(uri.getWaitTimeSecs().intValue(), 9);
210210
Assert.assertEquals(uri.getMaxRowsInBuffer().intValue(), 11);
211211
Assert.assertEquals(uri.getMaxRowsPerPage().intValue(), 7);
212-
Assert.assertEquals("false", uri.presignedUrlDisabled());
212+
Assert.assertFalse(uri.presignedUrlDisabled().booleanValue());
213213
Assert.assertEquals("null", uri.nullDisplay().toString());
214214
Assert.assertFalse(uri.getStrNullAsNull());
215215
}

docs/Connection.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ String url="jdbc:databend://databend:secret@0.0.0.0:8000/hello_databend";
8484
| SSL | Enable SSL | false | jdbc:databend://0.0.0.0:8000/hello_databend?SSL=true |
8585
| sslmode | SSL mode | disable | jdbc:databend://0.0.0.0:8000/hello_databend?sslmode=enable |
8686
| copy_purge | If True, the command will purge the files in the stage after they are loaded successfully into the table | false | jdbc:databend://0.0.0.0:8000/hello_databend?copy_purge=true |
87-
| presigned_url_disabled | Controls whether presigned URLs are used for data upload. Supported values: `auto` (enable for *.databend.com, *.databend.cn, *.tidbcloud.com hosts, disable otherwise), `detect` (probe the server to determine support), `true` (always disable), `false` (always enable) | auto | jdbc:databend://0.0.0.0:8000/hello_databend?presigned_url_disabled=auto |
87+
| presigned_url_disabled | whether use presigned url to upload data, generally if you use local disk as your storage layer, it should be set as true | false | jdbc:databend://0.0.0.0:8000/hello_databend?presigned_url_disabled=true |
88+
| presign | Controls presign mode for data upload. Values: `auto` (enable for *.databend.com, *.databend.cn, *.tidbcloud.com hosts, disable otherwise), `detect` (probe the server to determine support), `on` (always enable), `off` (always disable). When set, takes precedence over presigned_url_disabled | none | jdbc:databend://0.0.0.0:8000/hello_databend?presign=auto |
8889
| wait_time_secs | Restful query api blocking time, if the query is not finished, the api will block for wait_time_secs seconds | 10 | jdbc:databend://0.0.0.0:8000/hello_databend?wait_time_secs=10 |
8990
| max_rows_per_page | the maximum rows per page in response data body | 100000 | jdbc:databend://0.0.0.0:8000/default?max_rows_per_page=100000 |
9091
| null_display | null value display | \N | jdbc:databend://0.0.0.0:8000/hello_databend?null_display=null |

0 commit comments

Comments
 (0)