forked from apache/calcite-avatica
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a specific Driver class and 'jdbc:looker:' protocol support
- Loading branch information
1 parent
0463fdf
commit 761d6d6
Showing
6 changed files
with
112 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
core/src/main/java/org/apache/calcite/avatica/remote/looker/Driver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.calcite.avatica.remote.looker; | ||
|
||
import org.apache.calcite.avatica.AvaticaConnection; | ||
import org.apache.calcite.avatica.DriverVersion; | ||
import org.apache.calcite.avatica.Meta; | ||
import org.apache.calcite.avatica.UnregisteredDriver; | ||
import org.apache.calcite.avatica.remote.Service; | ||
import org.apache.calcite.avatica.remote.looker.utils.LookerSdkFactory; | ||
|
||
import com.looker.sdk.LookerSDK; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
public class Driver extends UnregisteredDriver { | ||
|
||
static { | ||
new Driver().register(); | ||
} | ||
|
||
public Driver() { | ||
super(); | ||
} | ||
|
||
public static final String CONNECT_STRING_PREFIX = "jdbc:looker:"; | ||
|
||
@Override | ||
protected DriverVersion createDriverVersion() { | ||
return DriverVersion.load( | ||
org.apache.calcite.avatica.remote.Driver.class, | ||
"org-apache-calcite-jdbc.properties", | ||
"Looker JDBC Driver", | ||
"unknown version", | ||
"Looker", | ||
"unknown version"); | ||
} | ||
|
||
@Override | ||
protected String getConnectStringPrefix() { | ||
return CONNECT_STRING_PREFIX; | ||
} | ||
|
||
@Override | ||
public Meta createMeta(AvaticaConnection connection) { | ||
final Service service = new LookerRemoteService(); | ||
connection.setService(service); | ||
return new LookerRemoteMeta(connection, service); | ||
} | ||
|
||
@Override public Connection connect(String url, Properties info) | ||
throws SQLException { | ||
AvaticaConnection conn = (AvaticaConnection) super.connect(url, info); | ||
|
||
if (conn == null) { | ||
// It's not an url for our driver | ||
return null; | ||
} | ||
Service service = conn.getService(); | ||
// the `looker` driver should always have a matching Service | ||
assert service instanceof LookerRemoteService; | ||
// create and set LookerSDK for the connection | ||
LookerSDK sdk = LookerSdkFactory.createSdk(conn.config().url(), info); | ||
((LookerRemoteService) service).setSdk(sdk); | ||
return conn; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
org.apache.calcite.avatica.remote.Driver | ||
org.apache.calcite.avatica.remote.looker.Driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters