Skip to content
Permalink
Browse files

0003906: HBase support as a load only node

  • Loading branch information...
jumpmind-josh committed Apr 9, 2019
1 parent 66f16be commit 29a7333fee50336b3a711c422de4fcb385ee1b17
@@ -492,6 +492,7 @@ include::derby.ad[]
include::firebird.ad[]
include::greenplum.ad[]
include::h2.ad[]
include::hbase.ad[]
include::hsqldb.ad[]
include::ignite.ad[]
include::informix.ad[]
@@ -0,0 +1,7 @@

=== HBase

The HBase database is a load only database in SymmetricDS. It does require the phoenix jdbc driver though to utilize it. This driver should be downloaded and placed in the /lib folder of SymmetricDS and restarted.

Tested with jar : phoenix-5.0.0-HBase-2.0-client.jar

@@ -35,6 +35,8 @@ apply from: symAssembleDir + '/common.gradle'
exclude group: 'com.fasterxml.jackson.core'
}

provided 'org.apache.phoenix:phoenix:5.0.0-HBase-2.0'

provided 'org.apache.httpcomponents:httpclient:4.5.4' // This is required by com.amazonaws:aws-java-sdk. It is called out here to upgrade the version because of a user's security concerns.

testCompile project(path: ':symmetric-util', configuration: 'testArtifacts')
@@ -58,5 +58,6 @@ private DatabaseNamesConstants() {
public final static String CASSANDRA = "cassandra";
public final static String KAFKA = "kafka";
public final static String SNOWFLAKE = "snowflake";
public final static String HBASE = "hbase";

}
@@ -27,6 +27,7 @@
import org.jumpmind.db.platform.firebird.FirebirdDialect1DdlBuilder;
import org.jumpmind.db.platform.greenplum.GreenplumDdlBuilder;
import org.jumpmind.db.platform.h2.H2DdlBuilder;
import org.jumpmind.db.platform.hbase.HbaseDdlBuilder;
import org.jumpmind.db.platform.hsqldb.HsqlDbDdlBuilder;
import org.jumpmind.db.platform.hsqldb2.HsqlDb2DdlBuilder;
import org.jumpmind.db.platform.informix.InformixDdlBuilder;
@@ -101,6 +102,8 @@ public static final IDdlBuilder createDdlBuilder(String databaseName) {
return new VoltDbDdlBuilder();
} else if (DatabaseNamesConstants.NUODB.equalsIgnoreCase(databaseName)) {
return new NuoDbDdlBuilder();
} else if (DatabaseNamesConstants.HBASE.equalsIgnoreCase(databaseName)) {
return new HbaseDdlBuilder();
} else {
return null;
}
@@ -23,6 +23,7 @@
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.db2.Db2zOsDmlStatement;
import org.jumpmind.db.platform.hbase.HbaseDmlStatement;
import org.jumpmind.db.platform.mssql.MsSqlDmlStatement;
import org.jumpmind.db.platform.mysql.MySqlDmlStatement;
import org.jumpmind.db.platform.oracle.OracleDmlStatement;
@@ -99,6 +100,10 @@ public static DmlStatement createDmlStatement(String databaseName, DmlType dmlTy
return new MsSqlDmlStatement(dmlType, catalogName, schemaName, tableName, keys, columns,
nullKeyValues, ddlBuilder.getDatabaseInfo(),
ddlBuilder.isDelimitedIdentifierModeOn(), textColumnExpression);
} else if (DatabaseNamesConstants.HBASE.equals(databaseName)) {
return new HbaseDmlStatement(dmlType, catalogName, schemaName, tableName, keys, columns,
nullKeyValues, ddlBuilder.getDatabaseInfo(),
ddlBuilder.isDelimitedIdentifierModeOn(), textColumnExpression);
} else {
return new DmlStatement(dmlType, catalogName, schemaName, tableName, keys, columns,
nullKeyValues, ddlBuilder.getDatabaseInfo(),
@@ -0,0 +1,56 @@
package org.jumpmind.db.platform.hbase;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.AbstractDdlBuilder;
import org.jumpmind.db.platform.DatabaseNamesConstants;

public class HbaseDdlBuilder extends AbstractDdlBuilder {

public HbaseDdlBuilder() {

super(DatabaseNamesConstants.HBASE);
}

@Override
protected void writePrimaryKeyStmt(Table table, Column[] primaryKeyColumns, StringBuilder ddl) {
ddl.append("CONSTRAINT NAME PRIMARY KEY (");
for (int idx = 0; idx < primaryKeyColumns.length; idx++) {
printIdentifier(getColumnName(primaryKeyColumns[idx]), ddl);
if (idx < primaryKeyColumns.length - 1) {
ddl.append(", ");
}
}
ddl.append(")");
}

@Override
public void writeCopyDataStatement(Table sourceTable, Table targetTable, LinkedHashMap<Column, Column> columnMap, StringBuilder ddl) {
ddl.append("UPSERT INTO ");
ddl.append(getFullyQualifiedTableNameShorten(targetTable));
ddl.append(" (");
for (Iterator<Column> columnIt = columnMap.values().iterator(); columnIt.hasNext();) {
printIdentifier(getColumnName((Column) columnIt.next()), ddl);
if (columnIt.hasNext()) {
ddl.append(",");
}
}
ddl.append(") SELECT ");
for (Iterator<Map.Entry<Column, Column>> columnsIt = columnMap.entrySet().iterator(); columnsIt.hasNext();) {
Map.Entry<Column, Column> entry = columnsIt.next();

writeCastExpression((Column) entry.getKey(), (Column) entry.getValue(), ddl);
if (columnsIt.hasNext()) {
ddl.append(",");
}
}
ddl.append(" FROM ");
ddl.append(getFullyQualifiedTableNameShorten(sourceTable));
printEndOfStatement(ddl);
}

}
@@ -0,0 +1,20 @@
package org.jumpmind.db.platform.hbase;

import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.sql.DmlStatement;

public class HbaseDmlStatement extends DmlStatement {

public HbaseDmlStatement(DmlType type, String catalogName, String schemaName, String tableName,
Column[] keysColumns, Column[] columns, boolean[] nullKeyValues,
DatabaseInfo databaseInfo, boolean useQuotedIdentifiers, String textColumnExpression) {
super(type, catalogName, schemaName, tableName, keysColumns, columns,
nullKeyValues, databaseInfo, useQuotedIdentifiers, textColumnExpression);
}

@Override
public String buildInsertSql(String tableName, Column[] keyColumns, Column[] columns) {
return super.buildInsertSql(tableName, keyColumns, columns).replaceAll("insert into", "upsert into");
}
}
@@ -42,6 +42,7 @@
import org.jumpmind.db.platform.generic.GenericJdbcDatabasePlatform;
import org.jumpmind.db.platform.greenplum.GreenplumPlatform;
import org.jumpmind.db.platform.h2.H2DatabasePlatform;
import org.jumpmind.db.platform.hbase.HbasePlatform;
import org.jumpmind.db.platform.hsqldb.HsqlDbDatabasePlatform;
import org.jumpmind.db.platform.hsqldb2.HsqlDb2DatabasePlatform;
import org.jumpmind.db.platform.informix.InformixDatabasePlatform;
@@ -119,6 +120,7 @@
addPlatform(platforms, DatabaseNamesConstants.NUODB, NuoDbDatabasePlatform.class);
addPlatform(platforms, DatabaseNamesConstants.TIBERO, TiberoDatabasePlatform.class);
addPlatform(platforms, DatabaseNamesConstants.RAIMA, RaimaDatabasePlatform.class);
addPlatform(platforms, "phoenix", HbasePlatform.class);

jdbcSubProtocolToPlatform.put(Db2DatabasePlatform.JDBC_SUBPROTOCOL, Db2DatabasePlatform.class);
jdbcSubProtocolToPlatform.put(DerbyDatabasePlatform.JDBC_SUBPROTOCOL, DerbyDatabasePlatform.class);
@@ -0,0 +1,31 @@
package org.jumpmind.db.platform.hbase;

import javax.sql.DataSource;

import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.IDdlBuilder;
import org.jumpmind.db.platform.generic.GenericJdbcDatabasePlatform;
import org.jumpmind.db.sql.SqlTemplateSettings;

public class HbasePlatform extends GenericJdbcDatabasePlatform {

public HbasePlatform(DataSource dataSource, SqlTemplateSettings settings) {
super(dataSource, settings);
}

@Override
public String getName() {
return DatabaseNamesConstants.HBASE;
}

@Override
protected IDdlBuilder createDdlBuilder() {
return new HbaseDdlBuilder();
}

@Override
public IDdlBuilder getDdlBuilder() {
return new HbaseDdlBuilder();
}

}

0 comments on commit 29a7333

Please sign in to comment.
You can’t perform that action at this time.