wudianlong 3 years ago
parent
commit
18bffc6af8

+ 0 - 6
dw-db/pom.xml

@@ -18,12 +18,6 @@
 
     <dependencies>
 
-        <dependency>
-            <groupId>org.apache.phoenix</groupId>
-            <artifactId>phoenix-core</artifactId>
-            <version>5.0.0-HBase-2.0</version>
-        </dependency>
-
     </dependencies>
 
 </project>

+ 23 - 18
dw-db/src/main/java/com/saga/hbase/phoenix/app/PhoenixDDL.java

@@ -1,32 +1,37 @@
 package com.saga.hbase.phoenix.app;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import com.saga.hbase.phoenix.bean.UsPopulation;
+import com.saga.hbase.phoenix.constant.PhoenixConstant;
 
-public class PhoenixDDL {
+import java.lang.reflect.Field;
+import java.sql.*;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
 
-    //Phoenix库名
-    public static final String HBASE_SCHEMA = "GMALL200821_REALTIME";
+public class PhoenixDDL {
 
-    //Phoenix驱动
-    public static final String PHOENIX_DRIVER = "org.apache.phoenix.jdbc.PhoenixDriver";
 
-    //Phoenix连接参数
-    public static final String PHOENIX_SERVER = "jdbc:phoenix:hadoop01,hadoop02,hadoop03:2181";
 
-    //ClickHouse驱动
-    public static final String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
+    public static void main(String[] args) throws ClassNotFoundException, SQLException {
 
-    //ClickHouse连接地址
-    public static final String CLICKHOUSE_URL = "jdbc:clickhouse://hadoop102:8123/default";
+        Class.forName(PhoenixConstant.PHOENIX_DRIVER);
+        Connection connection = DriverManager.getConnection(PhoenixConstant.PHOENIX_SERVER);
 
-    public static void main(String[] args) throws ClassNotFoundException, SQLException {
-        Class.forName(PHOENIX_DRIVER);
-        Connection connection = DriverManager.getConnection(PHOENIX_SERVER);
-        String schema = connection.getSchema();
+        Statement statement = connection.createStatement();
+        ResultSet resultSet = statement.executeQuery("select * from SYSTEM.US_POPULATION");
 
+        int columnCount = resultSet.getMetaData().getColumnCount();
+        while (resultSet.next()){
+            for (int i = 1; i <= columnCount; i++) {
+                String state = resultSet.getString(i);
+                System.out.print(state + " ");
+            }
 
+            System.out.println();
+        }
 
     }
+
+
 }

+ 42 - 0
dw-db/src/main/java/com/saga/hbase/phoenix/app/PhoenixDML.java

@@ -1,4 +1,46 @@
 package com.saga.hbase.phoenix.app;
 
+import com.saga.hbase.phoenix.bean.UsPopulation;
+import com.saga.hbase.phoenix.constant.PhoenixConstant;
+
+import java.lang.reflect.Field;
+import java.sql.*;
+import java.util.List;
+
+
 public class PhoenixDML {
+
+    //TODO 查询
+    public static <T> List<T> select(String schema, String tableName, T t) throws ClassNotFoundException, SQLException {
+        Class.forName(PhoenixConstant.PHOENIX_DRIVER);
+        Connection connection = DriverManager.getConnection(PhoenixConstant.PHOENIX_SERVER);
+
+        Statement statement = connection.createStatement();
+        ResultSet resultSet = statement.executeQuery("select * from SYSTEM.US_POPULATION");
+        Field[] fields = t.getClass().getDeclaredFields();
+
+        while (resultSet.next()){
+            UsPopulation usPopulation = new UsPopulation();
+
+            for (Field field : fields) {
+                String state = resultSet.getString(field.getName());
+            }
+        }
+        return null;
+    }
+
+    //TODO 更新
+    public Integer update(){
+        return 0;
+    }
+
+    //TODO 插入
+    public Integer insert(){
+        return 0;
+    }
+
+    //TODO 删除
+    public Integer delete(){
+        return 0;
+    }
 }

+ 90 - 0
dw-db/src/main/resources/hbase-site.xml

@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+/**
+ *
+ * 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.
+ */
+-->
+<configuration>
+
+<!--    <property>
+        <name>hbase.rootdir</name>
+        <value>hdfs://sagaCluster:8020/hbase</value>
+    </property>
+
+    <property>
+        <name>hbase.cluster.distributed</name>
+        <value>true</value>
+    </property>
+
+    <property>
+        <name>hbase.zookeeper.quorum</name>
+        <value>hadoop01,hadoop02,hadoop03</value>
+    </property>
+
+    <property>
+        <name>hbase.master.maxclockskew</name>
+        <value>180000</value>
+        <description>Time difference of regionserver from master</description>
+    </property>
+
+    <property>
+  	<name>hbase.unsafe.stream.capability.enforce</name>
+  	<value>false</value>
+    </property>-->
+    
+ 
+    <!-- 开启schema与namespace的对应关系 -->
+    <property>
+        <name>phoenix.schema.isNamespaceMappingEnabled</name>
+        <value>true</value>
+    </property>
+   
+<!--    <property>
+        <name>phoenix.schema.mapSystemTablesToNamespace</name>
+        <value>true</value>
+    </property>-->
+   <!-- 配置Hbase支持Phoenix创建二级索引 --> 
+    <!-- phoenix regionserver 配置参数 -->
+    <!--<property>
+	<name>hbase.regionserver.wal.codec</name>
+	<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
+    </property>
+
+    <property>
+	<name>hbase.region.server.rpc.scheduler.factory.class</name>
+	<value>org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory</value>
+    </property>
+
+    <property>
+	<name>hbase.rpc.controllerfactory.class</name>
+	<value>org.apache.hadoop.hbase.ipc.controller.ServerRpcControllerFactory</value>
+   </property>-->
+ 
+   <!-- phoenix master 配置参数 -->
+<!--   <property>
+	<name>hbase.master.loadbalancer.class</name>
+	<value>org.apache.phoenix.hbase.index.balancer.IndexLoadBalancer</value>
+   </property>
+
+   <property>
+	<name>hbase.coprocessor.master.classes</name>
+	<value>org.apache.phoenix.hbase.index.master.IndexMasterObserver</value>
+   </property>-->
+
+</configuration>

+ 0 - 18
dw-flink/pom.xml

@@ -14,28 +14,10 @@
     <properties>
         <maven.compiler.source>8</maven.compiler.source>
         <maven.compiler.target>8</maven.compiler.target>
-        <flink.version>1.13.6</flink.version>
     </properties>
 
     <dependencies>
 
-        <dependency>
-            <groupId>org.apache.flink</groupId>
-            <artifactId>flink-clients_2.12</artifactId>
-            <version>${flink.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.flink</groupId>
-            <artifactId>flink-table-planner-blink_2.12</artifactId>
-            <version>${flink.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.ververica</groupId>
-            <artifactId>flink-connector-mysql-cdc</artifactId>
-            <version>2.0.0</version>
-        </dependency>
 
     </dependencies>
 

+ 36 - 0
pom.xml

@@ -16,6 +16,7 @@
     <properties>
         <maven.compiler.source>8</maven.compiler.source>
         <maven.compiler.target>8</maven.compiler.target>
+        <flink.version>1.13.6</flink.version>
     </properties>
 
     <dependencies>
@@ -27,6 +28,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <version>3.1.3</version>
+        </dependency>
+
+        <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>8.0.21</version>
@@ -44,6 +51,35 @@
             <version>1.18.16</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.flink</groupId>
+            <artifactId>flink-clients_2.12</artifactId>
+            <version>${flink.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.flink</groupId>
+            <artifactId>flink-table-planner-blink_2.12</artifactId>
+            <version>${flink.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ververica</groupId>
+            <artifactId>flink-connector-mysql-cdc</artifactId>
+            <version>2.0.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.phoenix</groupId>
+            <artifactId>phoenix-core</artifactId>
+            <version>5.0.0-HBase-2.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>27.0-jre</version>
+        </dependency>
     </dependencies>
 
 </project>