MPP,它是一款 Shared Nothing 架构的分布式并行数据库集群,具备高性能、高可用、高扩展特性,可以为超大规模数据管理提供高性价比的通用计算平台,并广泛地用于支撑各类数据仓库系统、BI 系统和决策支持系统。
功 能 | 描 述 |
---|---|
结构化查询语言 | 符合 SQL 92 标准,支持 CREATE、ALTER、DROP 等 DDL 语法,支持 SELECT、INSERT、UPDATEDELETE、MERGE 等 DML 语法,支持单表,多表联合查询 |
数据类型 | INT、TINYINT、SMALLINT、BIGINT、DECIMAL、FLOAT、DOUBLE |
数值数据类型 | CHAR、VARCHAR、TEXT 字符数据类型 DATE、TIME、DATETIME、TIMESTAMP 日期类型 BLOB 二进制数据类型 |
数据库对象 | 提供了数据库,表,索引,视图,存储过程,自定义函数等常用数据库对象的创建,修改和删除操作,支持数据库用户的创建,删除操作,以及用户权限的分配与回收 |
行列混合存储 | 基于创建的物理表,可以实现行存列的创建,修改和删除 |
图形化工具 | 提供了企业管理工具和集群监控工具。 |
接口 | 符合并支持 C API、ODBC、JDBC、ADO.NET 等接口规范 |
外围工具 | 提供数据加载、集群备份/恢复、数据重分布等外围工具 |
MPP 采用完全并行的 MPP + Shared Nothing 的分布式扁平架构,这种架构中的每一个节点(node)都是独立的、自给的、节点之间对等,而且整个系统中不存在单点瓶颈,具有非常强的扩展性。
下载驱动:https://pan.baidu.com/s/1sV4XZbbmYtC0pAO6tewMTg
功能:将mysql中的数据表结构,自动在MPPDB中按照MPPDB语法批量创建表。
package com.epoint.HadoopAPIDemo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
public class MPPTestCreateTable {
private static String MYSQLUSERNAME = "root";
private static String MYSQLPASSWORD = "Gepoint";
private static String MYSQLDRIVER = "com.mysql.jdbc.Driver";
private static String MYSQLURL = "jdbc:mysql://100.2.5.221:3307/dep_fr_db";
private static String MYSQLDATABASE = "dep_fr_db";
private static String MPPDRIVER = "com.MPP.jdbc.Driver";
private static String MPPURL = "jdbc:MPP://100.2.5.1:5258/";
private static String MPPUSERNAME = "mpp";
private static String MPPPASSWORD = "h3c";
Connection mysqlconn = null;
Statement mysqlpstm = null;
ResultSet mysqlrs = null;
Connection mppconn = null;
Statement mppstm = null;
ResultSet mpprs = null;
String sql1 = " ";
String sql2 = " ";
String sql3 = " ";
String sql4 = " ";
String sql5 = " ";
String sql6 = " ";
public static void main(String[] args) throws Exception {
MPPTestCreateTable aidth = new MPPTestCreateTable();
aidth.getMYSQLConnection();
aidth.MYSQLReleaseResource();
aidth.getMPPConnection();
aidth.MPPReleaseResource();
aidth.CreateMPPTable();
// aidth.ImportDataToMPP();
System.out.println("程序已经执行完毕!请去waterdrop验证结果吧!!");
}
public void CreateMPPTable() {
mysqlconn = getMYSQLConnection();
mppconn = getMPPConnection();
try {
mppstm = mppconn.createStatement();
mysqlpstm = mysqlconn.createStatement();
int i = 0;
String sql = "SELECT table_schema\r\n" +
" ,table_name\r\n" +
" ,(\r\n" +
" CASE \r\n" +
" WHEN ORDINAL_POSITION = mincol\r\n" +
" AND ORDINAL_POSITION < maxcol\r\n" +
" THEN CONCAT (\"create table \"\r\n" +
" ,table_schema\r\n" +
" ,\".\"\r\n" +
" ,table_name\r\n" +
" ,\"(`\"\r\n" +
" ,column_name\r\n" +
" ,\"` \"\r\n" +
" ,COLUMN_TYPE\r\n" +
" ,\",\"\r\n" +
" )\r\n" +
" WHEN ORDINAL_POSITION = mincol\r\n" +
" AND ORDINAL_POSITION = maxcol\r\n" +
" THEN CONCAT (\"create table \"\r\n" +
" ,table_schema\r\n" +
" ,\".\"\r\n" +
" ,table_name\r\n" +
" ,\"(`\"\r\n" +
" ,column_name\r\n" +
" ,\"` \"\r\n" +
" ,COLUMN_TYPE\r\n" +
" ,\");\"\r\n" +
" )\r\n" +
" WHEN ORDINAL_POSITION > mincol\r\n" +
" AND ORDINAL_POSITION < maxcol\r\n" +
" THEN CONCAT (\r\n" +
" \"`\"\r\n" +
" ,column_name\r\n" +
" ,\"` \"\r\n" +
" ,COLUMN_TYPE\r\n" +
" ,\",\"\r\n" +
" )\r\n" +
" WHEN ORDINAL_POSITION = maxcol\r\n" +
" THEN CONCAT (\r\n" +
" \"`\"\r\n" +
" ,column_name\r\n" +
" ,\"` \"\r\n" +
" ,COLUMN_TYPE\r\n" +
" ,\");\"\r\n" +
" )\r\n" +
" END\r\n" +
" ) AS statement\r\n" +
" ,ORDINAL_POSITION\r\n" +
" ,maxcol\r\n" +
" ,mincol\r\n" +
"FROM (\r\n" +
" SELECT b.table_schema,b.table_name,b.ORDINAL_POSITION,b.column_name,\r\n" +
" (case\r\n" +
" when column_type = 'timestamp' then 'datetime'\r\n" +
" when column_type = 'bit(1)' then 'int(1)'\r\n" +
" else\r\n" +
" column_type\r\n" +
" end ) AS column_type\r\n" +
" ,a.maxcol\r\n" +
" ,a.mincol\r\n" +
" FROM (\r\n" +
" SELECT table_schema\r\n" +
" ,table_name\r\n" +
" ,max(ORDINAL_POSITION) maxcol\r\n" +
" ,min(ORDINAL_POSITION) mincol\r\n" +
" FROM information_schema.COLUMNS\r\n" +
" GROUP BY table_schema\r\n" +
" ,table_name\r\n" +
" ) a\r\n" +
" JOIN (\r\n" +
" SELECT table_schema\r\n" +
" ,table_name\r\n" +
" ,ORDINAL_POSITION\r\n" +
" ,column_name\r\n" +
" ,COLUMN_TYPE\r\n" +
" FROM information_schema.COLUMNS\r\n" +
" ORDER BY table_schema\r\n" +
" ,table_name\r\n" +
" ,ORDINAL_POSITION ASC\r\n" +
" ) b ON a.table_schema = b.table_schema\r\n" +
" AND a.table_name = b.table_name\r\n" +
" ) c\r\n" +
"WHERE table_schema = '"+MYSQLDATABASE+"'";
mysqlrs = mysqlpstm.executeQuery(sql);
while (mysqlrs.next()) {
sql1 = mysqlrs.getString(3);
sql2 = sql2 + sql1;
}
sql3 = "create database IF NOT EXISTS " + MYSQLDATABASE;
mppstm.execute(sql3);
System.out.println("-------------------建mpp表,表结构的语句为:" + sql2);
String[] sqls=sql2.split(";");
for (String m : sqls) {
mppstm.execute(m);
}
System.out.println("----------------------------------------建mpp表已结束!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
mppstm.close();
mysqlpstm.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
MYSQLReleaseResource();
MPPReleaseResource();
}
}
public void ImportDataToMPP() {
mysqlconn = getMYSQLConnection();
mppconn = getMPPConnection();
String sql = "select table_name from user_tables where num_rows > 0 order by table_name asc";
int i = 0;
try {
mysqlpstm = mysqlconn.createStatement();
mysqlrs = mysqlpstm.executeQuery(sql);
mppstm = mppconn.createStatement();
while (mysqlrs.next()) {
i = i + 1;
String table_name = mysqlrs.getString("table_name").replaceAll("\\$", "");
String sql7 = "insert into " + MYSQLDATABASE + "." + table_name + " select * from " + MYSQLDATABASE
+ "_ex." + table_name;
System.out.println("现在插入第"+i+"个表:"+sql7);
mppstm.execute(sql7);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
MYSQLReleaseResource();
MPPReleaseResource();
}
}
public Connection getMYSQLConnection() {
try {
Class.forName(MYSQLDRIVER);
mysqlconn = DriverManager.getConnection(MYSQLURL, MYSQLUSERNAME, MYSQLPASSWORD);
} catch (ClassNotFoundException e) {
throw new RuntimeException("class not find !", e);
} catch (SQLException e) {
throw new RuntimeException("get connection error!", e);
}
return mysqlconn;
}
public void MYSQLReleaseResource() {
if (mysqlrs != null) {
try {
mysqlrs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (mysqlpstm != null) {
try {
mysqlpstm.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (mysqlconn != null) {
try {
mysqlconn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public Connection getMPPConnection() {
try {
Class.forName(MPPDRIVER);
mppconn = DriverManager.getConnection(MPPURL, MPPUSERNAME, MPPPASSWORD);
} catch (ClassNotFoundException e) {
throw new RuntimeException("class not find !", e);
} catch (SQLException e) {
throw new RuntimeException("get connection error!", e);
}
return mppconn;
}
public void MPPReleaseResource() {
if (mpprs != null) {
try {
mpprs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (mppstm != null) {
try {
mppstm.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (mppconn != null) {
try {
mppconn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
package oa.epoint.com.mppdb;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.MPP.jdbc.jdbc2.optional.MPPDataSource;
public class MPPTest {
// JDBC连接串
static String url = "jdbc:MPP://100.2.5.1:5258/";
// mpp用户名
static String user = "mpp";
// mpp密码
static String passwd = "h3c";
public static void main(String args[]) {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.MPP.jdbc.Driver");
// 创建连接
MPPDataSource ds = new MPPDataSource();
ds.setUrl(url);
ds.setUser(user);
ds.setPassword(passwd);
conn = ds.getConnection();
System.out.println("MPP连接成功!");
st = conn.createStatement();
//创建库
st.execute("create database if not exists test;");
System.out.println("创建数据库成功!");
//使用库
st.execute("use test;");
System.out.println("使用数据库成功!");
//创建表
st.execute("create table if not exists test (id int,name varchar(20),age int);");
System.out.println("创建表成功!");
//插入数据
st.execute("insert into test values(1,'test',15)");
System.out.println("插入数据成功!");
// 查询TEST表内容
rs = st.executeQuery("SELECT * FROM test");
System.out.println("查询数据成功,等待反馈结果!");
while (rs.next()) {
System.out.print(rs.getString(1));
System.out.print(" ");
System.out.println(rs.getString(2));
}
rs.close();
st.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭连接
if (conn != null) {
try {
conn.close();
conn = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
jdbc:MPP://100.2.5.2:5258/test?rewriteBatchedStatements=true
com.MPP.jdbc.Driver