Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature-293][Connector] Add dameng connector #298

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.datavines</groupId>
<artifactId>datavines-connector-dm</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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.

-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datavines-connector-plugins</artifactId>
<groupId>io.datavines</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>datavines-connector-dm</artifactId>

<dependencies>
<dependency>
<groupId>io.datavines</groupId>
<artifactId>datavines-connector-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 io.datavines.connector.plugin;

import io.datavines.common.param.form.Validate;
import io.datavines.common.param.form.type.InputParam;

public class DmConfigBuilder extends JdbcConfigBuilder{

@Override
protected InputParam getDatabaseInput(boolean isEn) {
// DM only need schema.
// To avoid affecting the original code structure, the schema will be stored in the database here
return getInputParam("database",
isEn ? "schema" : "模式",
isEn ? "please enter schema, which is usually the same as the username" : "请填入模式, 一般和用户名相同", 1,
Validate.newBuilder().setRequired(true).setMessage(isEn ? "please enter schema" : "请填入模式").build(),
null);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 io.datavines.connector.plugin;

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DmConnector extends JdbcConnector {
@Override
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
return new DmDataSourceInfo(jdbcConnectionInfo);
}

@Override
protected ResultSet getMetadataDatabases(Connection connection) throws SQLException {
DatabaseMetaData metaData = connection.getMetaData();
// DM only need schema
return metaData.getSchemas();
}

protected ResultSet getMetadataTables(DatabaseMetaData metaData, String catalog, String schema) throws SQLException {
// DM only need schema
return metaData.getTables(null, schema, null, TABLE_TYPES);
}

protected ResultSet getMetadataColumns(DatabaseMetaData metaData,
String catalog, String schema,
String tableName, String columnName) throws SQLException {
// DM only need schema
return metaData.getColumns(null, schema, tableName, columnName);
}

protected ResultSet getPrimaryKeys(DatabaseMetaData metaData,String catalog, String schema, String tableName) throws SQLException {
// DM only need schema
return metaData.getPrimaryKeys(null, schema, tableName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 io.datavines.connector.plugin;

import io.datavines.connector.api.*;

public class DmConnectorFactory extends AbstractJdbcConnectorFactory {
@Override
public Connector getConnector() {
return new DmConnector();
}

@Override
public Dialect getDialect() {
return new DmDialect();
}

@Override
public ConnectorParameterConverter getConnectorParameterConverter() {
return new DmConnectorParameterConverter();
}

@Override
public Executor getExecutor() {
return new DmExecutor();
}

@Override
public ConfigBuilder getConfigBuilder() {
return new DmConfigBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 io.datavines.connector.plugin;

import io.datavines.common.utils.StringUtils;
import java.util.Map;
import static io.datavines.common.ConfigConstants.*;
import static io.datavines.common.ConfigConstants.PROPERTIES;

public class DmConnectorParameterConverter extends JdbcConnectorParameterConverter {
@Override
protected String getUrl(Map<String, Object> parameter) {
// in dm jdbc url, the database is not need.
String url = String.format("jdbc:dm://%s:%s?schema=%s",
parameter.get(HOST),
parameter.get(PORT),
parameter.get(DATABASE));
String properties = (String)parameter.get(PROPERTIES);
if (StringUtils.isNotEmpty(properties)) {
url += "&" + properties;
}
return url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 io.datavines.connector.plugin;

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DmDataSourceInfo extends BaseJdbcDataSourceInfo {
private final Logger logger = LoggerFactory.getLogger(DmDataSourceInfo.class);

public DmDataSourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
super(jdbcConnectionInfo);
}

@Override
public String getAddress() {
return "jdbc:dm://"+getHost()+":"+getPort();
}

@Override
public String getDriverClass() {
return "dm.jdbc.driver.DmDriver";
}

@Override
public String getType() {
return "dameng";
}

@Override
protected String getSeparator() {
return "?";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 io.datavines.connector.plugin;

public class DmDialect extends JdbcDialect{
@Override
public String getDriver() {
return "dm.jdbc.driver.DmDriver";
}

@Override
public boolean invalidateItemCanOutput() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 io.datavines.connector.plugin;

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;

public class DmExecutor extends BaseJdbcExecutor{

@Override
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
return new DmDataSourceInfo(jdbcConnectionInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dm=io.datavines.connector.plugin.DmConnectorFactory
1 change: 1 addition & 0 deletions datavines-connector/datavines-connector-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<module>datavines-connector-databend</module>
<module>datavines-connector-mongodb</module>
<module>datavines-connector-sqlserver</module>
<module>datavines-connector-dm</module>
</modules>


Expand Down
1 change: 1 addition & 0 deletions datavines-dist/src/main/assembly/datavines-bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<include>org.postgresql:postgresql</include>
<include>com.facebook.presto:presto-jdbc</include>
<include>io.trino:trino-jdbc</include>
<include>com.dameng:DmJdbcDriver18</include>
</includes>
</dependencySet>
</dependencySets>
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<commons-configuration.version>1.8</commons-configuration.version>
<hive.version>2.1.0</hive.version>
<sqlserver.version>6.1.0.jre8</sqlserver.version>
<dameng.version>8.1.2.141</dameng.version>
<hikari.version>4.0.3</hikari.version>
<spring.version>5.3.12</spring.version>
<kerberos.version>1.0.1.RELEASE</kerberos.version>
Expand Down Expand Up @@ -568,6 +569,11 @@
<artifactId>mssql-jdbc</artifactId>
<version>${sqlserver.version}</version>
</dependency>
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>${dameng.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
Expand Down
Loading