spark连接phoenix操作Hbase报连接错误

java.sql.SQLException: ERROR 102 (08001): Malformed connection url. :jdbc:phoenix:192.168.145.80:2181:/hbase:2181:/hbase;
at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:422)
at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver$ConnectionInfo.getMalFormedUrlException(PhoenixEmbeddedDriver.java:189)
at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver$ConnectionInfo.create(PhoenixEmbeddedDriver.java:235)
at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:213)
at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.createConnection(PhoenixEmbeddedDriver.java:135)
at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:202)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.apache.phoenix.mapreduce.util.ConnectionUtil.getConnection(ConnectionUtil.java:98)
at org.apache.phoenix.mapreduce.util.ConnectionUtil.getOutputConnection(ConnectionUtil.java:82)
at org.apache.phoenix.mapreduce.util.ConnectionUtil.getOutputConnection(ConnectionUtil.java:70)
at org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil.getUpsertColumnMetadataList(PhoenixConfigurationUtil.java:230)
at org.apache.phoenix.spark.DataFrameFunctions$$anonfun$2.apply(DataFrameFunctions.scala:45)
at org.apache.phoenix.spark.DataFrameFunctions$$anonfun$2.apply(DataFrameFunctions.scala:41)
at org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1$$anonfun$apply$20.apply(RDD.scala:710)
at org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1$$anonfun$apply$20.apply(RDD.scala:710)
at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:306)
at org.apache.spark.rdd.RDD.iterator(RDD.scala:270)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
at org.apache.spark.scheduler.Task.run(Task.scala:89)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
18/09/30 17:20:42 ERROR Executor: Exception in task 4.0 in stage 0.0 (TID 4)


代码:

import com.google.common.collect.ImmutableMap;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.DataFrameWriter;
import org.apache.spark.sql.SQLContext;
import org.apache.spark.sql.SaveMode;

import java.util.ArrayList;

public class SparkUpsertPhoenixUtil {

public static void main(String[] args) {
SparkConf conf = new SparkConf().setAppName("SparkUpsertPhoenixUtil").setMaster("local[*]");

JavaSparkContext jsc = new JavaSparkContext(conf);

SQLContext sqlContext = new SQLContext(jsc);

String dayHour = "0912";
String yearMonth = "201809";
String lonLat = "1163279399729";
String ternimated = "0x001";
String routeId = "0R01";
String carTrackLonLat = "1163279399729";
String carTrackKicatTime = "201809251020-201809251025-201809251030-201809251040";
String carTrackSpeed = "40-60-80-60";
String carTrackHdop = "4-3-5-4";
String carTrackDire = "270-272-180-180";
String carTrackAliude = "12-14-13-10";
String carTrackRoadId = "0r003-0r004-0r005";
String carTravelName = "人民大学(地铁站)-鸿福宾馆";
String carTravelDistance = "2.1";
String carTravelTime = "20";
String carTravelAvgSpeed = "60";
String carTravelMaxSpeed = "80";
String carTravelUpSpeed = "116.341316,39.967544-权金城-80";
String carTravelBrakTimes = "3";
String carTravelNost = "1";
String carTravelNoa = "3";
String originalDataRouteId = "0R01";

TravelPojo travelPojo = new TravelPojo();

travelPojo.setTravelPojo(dayHour, yearMonth, lonLat, ternimated, routeId, carTrackLonLat, carTrackKicatTime, carTrackSpeed, carTrackHdop, carTrackDire, carTrackAliude, carTrackRoadId, carTravelName, carTravelDistance, carTravelTime, carTravelAvgSpeed, carTravelMaxSpeed, carTravelUpSpeed, carTravelBrakTimes, carTravelNost, carTravelNoa, originalDataRouteId);

ArrayList<TravelPojo> travelList = new ArrayList<TravelPojo>();
travelList.add(travelPojo);
JavaRDD<TravelPojo> travelPojoJavaRDD = jsc.parallelize(travelList);

DataFrame dataFrame = sqlContext.createDataFrame(travelPojoJavaRDD, travelPojo.getClass());

DataFrameWriter mode = dataFrame.write().format("org.apache.phoenix.spark").mode(SaveMode.Overwrite);

DataFrameWriter options = mode.options(ImmutableMap.of("driver", "org.apache.phoenix.jdbc.PhoenixDriver", "zkUrl",
"jdbc:phoenix:192.168.145.80:2181:/hbase", "table", "MAPBARTRAVEL"));
options.save();
}
}

import java.io.Serializable;

public class TravelPojo implements Serializable {
private String dayHour;
private String yearMonth;
private String lonLat;
private String ternimated;
private String routeId;
private String carTrackLonLat;
private String carTrackKicatTime;
private String carTrackSpeed;
private String carTrackHdop;
private String carTrackDire;
private String carTrackAliude;
private String carTrackRoadId;
private String carTravelName;
private String carTravelDistance;
private String carTravelTime;
private String carTravelAvgSpeed;
private String carTravelMaxSpeed;
private String carTravelUpSpeed;
private String carTravelBrakTimes;
private String carTravelNost;
private String carTravelNoa;
private String originalDataRouteId;

public String getDayHour() {
return dayHour;
}

public void setDayHour(String dayHour) {
this.dayHour = dayHour;
}

public String getYearMonth() {
return yearMonth;
}

public void setYearMonth(String yearMonth) {
this.yearMonth = yearMonth;
}

public String getLonLat() {
return lonLat;
}

public void setLonLat(String lonLat) {
this.lonLat = lonLat;
}

public String getTernimated() {
return ternimated;
}

public void setTernimated(String ternimated) {
this.ternimated = ternimated;
}

public String getRouteId() {
return routeId;
}

public void setRouteId(String routeId) {
this.routeId = routeId;
}

public String getCarTrackLonLat() {
return carTrackLonLat;
}

public void setCarTrackLonLat(String carTrackLonLat) {
this.carTrackLonLat = carTrackLonLat;
}

public String getCarTrackKicatTime() {
return carTrackKicatTime;
}

public void setCarTrackKicatTime(String carTrackKicatTime) {
this.carTrackKicatTime = carTrackKicatTime;
}

public String getCarTrackSpeed() {
return carTrackSpeed;
}

public void setCarTrackSpeed(String carTrackSpeed) {
this.carTrackSpeed = carTrackSpeed;
}

public String getCarTrackHdop() {
return carTrackHdop;
}

public void setCarTrackHdop(String carTrackHdop) {
this.carTrackHdop = carTrackHdop;
}

public String getCarTrackDire() {
return carTrackDire;
}

public void setCarTrackDire(String carTrackDire) {
this.carTrackDire = carTrackDire;
}

public String getCarTrackAliude() {
return carTrackAliude;
}

public void setCarTrackAliude(String carTrackAliude) {
this.carTrackAliude = carTrackAliude;
}

public String getCarTrackRoadId() {
return carTrackRoadId;
}

public void setCarTrackRoadId(String carTrackRoadId) {
this.carTrackRoadId = carTrackRoadId;
}

public String getCarTravelName() {
return carTravelName;
}

public void setCarTravelName(String carTravelName) {
this.carTravelName = carTravelName;
}

public String getCarTravelDistance() {
return carTravelDistance;
}

public void setCarTravelDistance(String carTravelDistance) {
this.carTravelDistance = carTravelDistance;
}

public String getCarTravelTime() {
return carTravelTime;
}

public void setCarTravelTime(String carTravelTime) {
this.carTravelTime = carTravelTime;
}

public String getCarTravelAvgSpeed() {
return carTravelAvgSpeed;
}

public void setCarTravelAvgSpeed(String carTravelAvgSpeed) {
this.carTravelAvgSpeed = carTravelAvgSpeed;
}

public String getCarTravelMaxSpeed() {
return carTravelMaxSpeed;
}

public void setCarTravelMaxSpeed(String carTravelMaxSpeed) {
this.carTravelMaxSpeed = carTravelMaxSpeed;
}

public String getCarTravelUpSpeed() {
return carTravelUpSpeed;
}

public void setCarTravelUpSpeed(String carTravelUpSpeed) {
this.carTravelUpSpeed = carTravelUpSpeed;
}

public String getCarTravelBrakTimes() {
return carTravelBrakTimes;
}

public void setCarTravelBrakTimes(String carTravelBrakTimes) {
this.carTravelBrakTimes = carTravelBrakTimes;
}

public String getCarTravelNost() {
return carTravelNost;
}

public void setCarTravelNost(String carTravelNost) {
this.carTravelNost = carTravelNost;
}

public String getCarTravelNoa() {
return carTravelNoa;
}

public void setCarTravelNoa(String carTravelNoa) {
this.carTravelNoa = carTravelNoa;
}

public String getOriginalDataRouteId() {
return originalDataRouteId;
}

public void setOriginalDataRouteId(String originalDataRouteId) {
this.originalDataRouteId = originalDataRouteId;
}

public void setTravelPojo(String dayHour, String yearMonth, String lonLat, String ternimated, String routeId, String carTrackLonLat, String carTrackKicatTime, String carTrackSpeed, String carTrackHdop, String carTrackDire, String carTrackAliude, String carTrackRoadId, String carTravelName, String carTravelDistance, String carTravelTime, String carTravelAvgSpeed, String carTravelMaxSpeed, String carTravelUpSpeed, String carTravelBrakTimes, String carTravelNost, String carTravelNoa, String originalDataRouteId) {
this.dayHour = dayHour;
this.yearMonth = yearMonth;
this.lonLat = lonLat;
this.ternimated = ternimated;
this.routeId = routeId;
this.carTrackLonLat = carTrackLonLat;
this.carTrackKicatTime = carTrackKicatTime;
this.carTrackSpeed = carTrackSpeed;
this.carTrackHdop = carTrackHdop;
this.carTrackDire = carTrackDire;
this.carTrackAliude = carTrackAliude;
this.carTrackRoadId = carTrackRoadId;
this.carTravelName = carTravelName;
this.carTravelDistance = carTravelDistance;
this.carTravelTime = carTravelTime;
this.carTravelAvgSpeed = carTravelAvgSpeed;
this.carTravelMaxSpeed = carTravelMaxSpeed;
this.carTravelUpSpeed = carTravelUpSpeed;
this.carTravelBrakTimes = carTravelBrakTimes;
this.carTravelNost = carTravelNost;
this.carTravelNoa = carTravelNoa;
this.originalDataRouteId = originalDataRouteId;
}

@Override
public String toString() {
return "TravelPojo{" +
"dayHour='" + dayHour + '\'' +
", yearMonth='" + yearMonth + '\'' +
", lonLat='" + lonLat + '\'' +
", ternimated='" + ternimated + '\'' +
", routeId='" + routeId + '\'' +
", carTrackLonLat='" + carTrackLonLat + '\'' +
", carTrackKicatTime='" + carTrackKicatTime + '\'' +
", carTrackSpeed='" + carTrackSpeed + '\'' +
", carTrackHdop='" + carTrackHdop + '\'' +
", carTrackDire='" + carTrackDire + '\'' +
", carTrackAliude='" + carTrackAliude + '\'' +
", carTrackRoadId='" + carTrackRoadId + '\'' +
", carTravelName='" + carTravelName + '\'' +
", carTravelDistance='" + carTravelDistance + '\'' +
", carTravelTime='" + carTravelTime + '\'' +
", carTravelAvgSpeed='" + carTravelAvgSpeed + '\'' +
", carTravelMaxSpeed='" + carTravelMaxSpeed + '\'' +
", carTravelUpSpeed='" + carTravelUpSpeed + '\'' +
", carTravelBrakTimes='" + carTravelBrakTimes + '\'' +
", carTravelNost='" + carTravelNost + '\'' +
", carTravelNoa='" + carTravelNoa + '\'' +
", originalDataRouteId='" + originalDataRouteId + '\'' +
'}';
}
}
已邀请:

jinqian

赞同来自:

url只填​jdbc:phoenix:192.168.145.80 就可以了

Marshal丶张

赞同来自:

去掉之后连接就超时了,连接不到那台服务器
18/09/30 17:45:07 INFO ClientCnxn: Opening socket connection to server 116.213.115.122/116.213.115.122:2181. Will not attempt to authenticate using SASL (unknown error)
18/09/30 17:45:28 WARN ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection timed out: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
 

anbbrr - 大数据工程师

赞同来自:

问下这个问题你解决了吗?我是也是这个问题

要回复问题请先登录注册


中国HBase技术社区微信公众号:
hbasegroup

欢迎加入HBase生态+Spark社区钉钉大群