Skip to content

Commit ed811b6

Browse files
author
Jonny Dixon
committed
Update to enable legacy dialect
1 parent 556535c commit ed811b6

5 files changed

Lines changed: 113 additions & 20 deletions

File tree

dremio-sybasearp-plugin-4.1.0.jar

-13.8 KB
Binary file not shown.

dremio-sybasearp-plugin.jar

2.12 KB
Binary file not shown.

src/main/java/com/dremio/exec/store/jdbc/conf/SybaseConf.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
package com.dremio.exec.store.jdbc.conf;
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
20-
import static java.lang.String.format;
21-
22-
import java.io.IOException;
23-
import java.net.URI;
24-
import java.sql.SQLException;
2520
import java.util.Properties;
2621

2722
import javax.validation.constraints.Max;
@@ -38,8 +33,7 @@
3833
import com.dremio.exec.store.jdbc.JdbcStoragePlugin;
3934
import com.dremio.exec.store.jdbc.JdbcStoragePlugin.Config;
4035
import com.dremio.exec.store.jdbc.dialect.arp.ArpDialect;
41-
import com.dremio.security.CredentialsService;
42-
import com.dremio.security.PasswordCredentials;
36+
import com.dremio.exec.store.jdbc.dialect.SybaseDialect;
4337
import com.google.common.annotations.VisibleForTesting;
4438
import com.google.common.base.Strings;
4539

@@ -53,7 +47,7 @@
5347
public class SybaseConf extends AbstractArpConf<SybaseConf> {
5448
private static final String ARP_FILENAME = "arp/implementation/sybase-arp.yaml";
5549
private static final ArpDialect ARP_DIALECT =
56-
AbstractArpConf.loadArpFile(ARP_FILENAME, (ArpDialect::new));
50+
AbstractArpConf.loadArpFile(ARP_FILENAME, (SybaseDialect::new));
5751
private static final String DRIVER = "com.sybase.jdbc4.jdbc.SybDriver";
5852

5953
@NotBlank
@@ -85,7 +79,6 @@ public class SybaseConf extends AbstractArpConf<SybaseConf> {
8579

8680
@Tag(6)
8781
@DisplayMetadata(label = "Encrypt connection")
88-
@NotMetadataImpacting
8982
public boolean useSsl = false;
9083

9184
@Tag(7)
@@ -131,7 +124,7 @@ private String toJdbcConnectionString() {
131124
final int port = Integer.parseInt(portAsString);
132125

133126
if (!Strings.isNullOrEmpty(this.database)) {
134-
return String.format("jdbc:sybase:Tds:%s:%s/%s", hostname, port, database);
127+
return String.format("jdbc:sybase:Tds:%s:%s/%s", hostname, port, this.database);
135128
} else {
136129
return String.format("jdbc:sybase:Tds:%s:%s", hostname, port);
137130
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (C) 2017-2019 Dremio Corporation. This file is confidential and private property.
3+
*/
4+
package com.dremio.exec.store.jdbc.dialect;
5+
6+
import com.dremio.exec.store.jdbc.dialect.arp.ArpYaml;
7+
import org.apache.calcite.sql.SqlNode;
8+
import org.apache.calcite.sql.SqlCall;
9+
import org.apache.calcite.sql.SqlSelect;
10+
import org.apache.calcite.sql.SqlSelectOperator;
11+
import org.apache.calcite.sql.SqlSelectKeyword;
12+
import org.apache.calcite.sql.SqlLiteral;
13+
import org.apache.calcite.sql.SqlNodeList;
14+
import org.apache.calcite.sql.SqlWriter;
15+
import org.apache.calcite.sql.parser.SqlParserPos;
16+
import com.dremio.exec.store.jdbc.dialect.arp.ArpDialect;
17+
18+
/*
19+
* Licensed to the Apache Software Foundation (ASF) under one or more
20+
* contributor license agreements. See the NOTICE file distributed with
21+
* this work for additional information regarding copyright ownership.
22+
* The ASF licenses this file to you under the Apache License, Version 2.0
23+
* (the "License"); you may not use this file except in compliance with
24+
* the License. You may obtain a copy of the License at
25+
*
26+
* http://www.apache.org/licenses/LICENSE-2.0
27+
*
28+
* Unless required by applicable law or agreed to in writing, software
29+
* distributed under the License is distributed on an "AS IS" BASIS,
30+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31+
* See the License for the specific language governing permissions and
32+
* limitations under the License.
33+
*/
34+
35+
36+
/**
37+
* A <code>SqlDialect</code> implementation for the Sybase database.
38+
*/
39+
public class SybaseDialect extends ArpDialect {
40+
41+
/** Creates a SybaseSqlDialect. */
42+
public SybaseDialect(ArpYaml yaml) {
43+
super(yaml);
44+
}
45+
46+
@Override
47+
public boolean hasImplicitTableAlias() {
48+
return false;
49+
}
50+
51+
@Override
52+
public void unparseCall(final SqlWriter writer, final SqlCall call, final int leftPrec, final int rightPrec) {
53+
// Transform SqlSelect nodes that have a fetch node to be SqlSelect nodes with a TOP and no fetch.
54+
if (call instanceof SqlSelect) {
55+
final SqlSelect select = (SqlSelect) call;
56+
57+
// Transform SqlSelect nodes that have a fetch node without offset to be
58+
// SqlSelect nodes with a TOP and no fetch.
59+
if (null != select.getFetch()
60+
&& (null == select.getOffset() || 0 == ((SqlLiteral) select.getOffset()).getValueAs(Long.class))) {
61+
final SqlNodeList keywords = new SqlNodeList(SqlParserPos.ZERO);
62+
63+
// Add the DISTINCT or ALL keywords if the original Select had either. (Only can have one of these).
64+
// These must go before TOP.
65+
if (null != select.getModifierNode(SqlSelectKeyword.DISTINCT)) {
66+
keywords.add(select.getModifierNode(SqlSelectKeyword.DISTINCT));
67+
} else if (null != select.getModifierNode(SqlSelectKeyword.ALL)) {
68+
keywords.add(select.getModifierNode(SqlSelectKeyword.ALL));
69+
}
70+
71+
// Inject the TOP <literal> nodes.
72+
keywords.add(SqlSelectExtraKeyword.TOP.symbol(SqlParserPos.ZERO));
73+
keywords.add(select.getFetch());
74+
75+
// Unparse a version of this select with TOP injected and the FETCH removed.
76+
final SqlSelect modifiedSelect = SqlSelectOperator.INSTANCE.createCall(
77+
keywords,
78+
select.getSelectList(),
79+
select.getFrom(),
80+
select.getWhere(),
81+
select.getGroup(),
82+
select.getHaving(),
83+
select.getWindowList(),
84+
select.getOrderList(),
85+
null,
86+
null,
87+
SqlParserPos.ZERO);
88+
89+
super.unparseCall(writer, modifiedSelect, leftPrec, rightPrec);
90+
} else {
91+
super.unparseCall(writer, call, leftPrec, rightPrec);
92+
}
93+
} else {
94+
// Fall through to the base class implementation.
95+
super.unparseCall(writer, call, leftPrec, rightPrec);
96+
}
97+
}
98+
}
99+
100+
// End SybaseDialect.java

src/main/resources/arp/implementation/sybase-arp.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,21 @@ relational_algebra:
246246
project:
247247
enable: true
248248
join:
249-
enable: false
249+
enable: true
250250
cross:
251251
enable: false
252252
inner:
253-
enable: false
254-
inequality: false
253+
enable: true
254+
inequality: true
255255
left:
256-
enable: false
257-
inequality: false
256+
enable: true
257+
inequality: true
258258
right:
259-
enable: false
260-
inequality: false
259+
enable: true
260+
inequality: true
261261
full:
262-
enable: false
263-
inequality: false
262+
enable: true
263+
inequality: true
264264
sort:
265265
enable: true
266266
order_by:
@@ -272,7 +272,7 @@ relational_algebra:
272272
offset_only:
273273
enable: false
274274
fetch_only:
275-
enable: false
275+
enable: true
276276
union:
277277
enable: true
278278
union_all:

0 commit comments

Comments
 (0)