使用产品:supermap-iobjects-for-spark-10.1.2-20210331
oracle数据源是可以用idesktop打开的,下面是完整的测试代码:
val conf = new SparkConf().setAppName("Guide Example")
conf.set("spark.serializer","org.apache.spark.serializer.KryoSerializer")
conf.set("spark.kryo.registrator", classOf[GeoMesaSparkKryoRegistrator].getName)
conf.setMaster("local[*]")
val sc = new SparkContext(conf)
val params = new util.HashMap[String, java.io.Serializable]()
params.put("dbtype", "oracle")
params.put("host", "localhost")
params.put("port", 1521)//端口号
params.put("schema", "qjdc")//oracle读取时设置为与“User”用户名参数一致即可
params.put("database", "orcl")//数据库名
params.put("user", "qjdc")//用户名
params.put("passwd", "salis")//密码
params.put("numPartitions", 64)//oracle读取时的分区数量,数据量大时可适当增大该值,只用于读取
params.put("partitionField", "partfield")//分区依赖的字段名,有主键时可缺省默认使用主键,无主键时"partitionField"与"predicates"需有一个有效值
params.put("providerType", "JDBC")//引擎类型的唯一标识
val featurerdd = FeatureRDDProviderFactory(params).rdd(new Configuration(), sc, params, new Query("qjdckj_zd_xz"))
val param2 = new util.HashMap[String,java.io.Serializable]()
param2.put("dbType", "UDBX")
param2.put("server", "D:\\2-code\\2-test\\test.udbx")
param2.put("providerType", "SDX")
FeatureRDDProviderFactory(param2).save(featurerdd, param2, featurerdd.schema.getTypeName)
报错信息:
Exception in thread "main" java.sql.SQLRecoverableException: IO 错误: Undefined Error
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:774)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at com.supermap.bdt.rddprovider.jdbc.OracleFeatureRDD.<init>(OracleFeatureRDD.scala:31)
at com.supermap.bdt.rddprovider.jdbc.OracleFeatureRDD$.apply(OracleFeatureRDD.scala:314)
at com.supermap.bdt.rddprovider.jdbc.OracleFeatureRDDProvider.rdd(OracleFeatureRDDProvider.scala:39)
at com.example.GuideExample$.main(GuideExample.scala:40)
at com.example.GuideExample.main(GuideExample.scala)
Caused by: oracle.net.ns.NetException: Undefined Error
at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:271)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:317)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518)
... 10 more