我在没有安装Spark的情况下使用intellij项目加载Spark。
val spark = SparkSession.builder().config(sparkConf).getOrCreate()
我已经使用
将com.spark.databricks.xml添加到了spark中sparkConf.set("spark.driver.extraClassPath", "C:/.../spark-xml_2.11-0.4.1.jar")
sparkConf.setExecutorEnv("spark.driver.extraClassPath", "C:/.../spark-xml_2.11-0.4.1.jar")
sparkConf.set("spark.executor.extraClassPath", "C:/.../spark-xml_2.11-0.4.1.jar")
sparkConf.setExecutorEnv("spark.executor.extraClassPath", "C:/.../spark-xml_2.11-0.4.1.jar")
sparkConf.setJars(Array("C:/.../spark-xml_2.11-0.4.1.jar" ))
和
spark.sparkContext.addJar("C:/.../spark-xml_2.10-0.2.0.jar")
但是在尝试使用spark.read.format ("com.databricks.spark.xml")
时,我得到了异常"无法找到数据源:com.databricks.spark.xml。请在http://spark.apache.org/third-party-projects.html"。
我该如何解决这个问题?我知道建议使用spark-shell添加罐子,但我没有火花壳,因为我没有安装火花......
答案 0 :(得分:1)
如果您有一个带有maven / sbt的项目,您可以添加spark-xml依赖项,如下所述:
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ardef` (
`ardef_id` int(11) NOT NULL AUTO_INCREMENT,
`ardef` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`ardef_id`),
KEY `fk_arabic-definitions_idx` (`Terms_id`),
KEY `ardefix` (`ardef`),
CONSTRAINT `fk_arabic-definitions` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ardef`
--
CREATE TABLE `arterms` (
`arterms_id` int(11) NOT NULL AUTO_INCREMENT,
`Terms_arma` varchar(128) DEFAULT NULL,
`Terms_ardz` varchar(128) DEFAULT NULL,
`Terms_arbh` varchar(128) DEFAULT NULL,
`Terms_artd` varchar(128) DEFAULT NULL,
`Terms_arkm` varchar(128) DEFAULT NULL,
`Terms_ardj` varchar(128) DEFAULT NULL,
`Terms_areg` varchar(128) DEFAULT NULL,
`Terms_arer` varchar(128) DEFAULT NULL,
`Terms_ariq` varchar(128) DEFAULT NULL,
`Terms_aril` varchar(128) DEFAULT NULL,
`Terms_arjo` varchar(128) DEFAULT NULL,
`Terms_arkw` varchar(128) DEFAULT NULL,
`Terms_arlb` varchar(128) DEFAULT NULL,
`Terms_arly` varchar(128) DEFAULT NULL,
`Terms_armt` varchar(128) DEFAULT NULL,
`Terms_armr` varchar(128) DEFAULT NULL,
`Terms_arom` varchar(128) DEFAULT NULL,
`Terms_arps` varchar(128) DEFAULT NULL,
`Terms_arqa` varchar(128) DEFAULT NULL,
`Terms_arsa` varchar(128) DEFAULT NULL,
`Terms_arso` varchar(128) DEFAULT NULL,
`Terms_arsd` varchar(128) DEFAULT NULL,
`Terms_arsy` varchar(128) DEFAULT NULL,
`Terms_artz` varchar(128) DEFAULT NULL,
`Terms_artn` varchar(128) DEFAULT NULL,
`Terms_arae` varchar(128) DEFAULT NULL,
`Terms_arye` varchar(128) DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`arterms_id`),
KEY `fk_arterms_idx` (`Terms_id`),
CONSTRAINT `fk_arterms` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `arterms`
--
CREATE TABLE `dedef` (
`dedef_id` int(11) NOT NULL AUTO_INCREMENT,
`dedef` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`dedef_id`),
KEY `fk_german_definitions_1_idx` (`Terms_id`),
KEY `dedefix` (`dedef`),
CONSTRAINT `fk_german_definitions_1` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `dedef`
--
CREATE TABLE `determs` (
`Terms_id` int(11) NOT NULL AUTO_INCREMENT,
`Terms_de` varchar(128) DEFAULT NULL,
`Terms_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Time when record was updated.',
`Terms_created` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time when record was created.',
PRIMARY KEY (`Terms_id`),
KEY `determ` (`Terms_de`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `endef` (
`endef_id` int(11) NOT NULL AUTO_INCREMENT,
`endef` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`endef_id`),
KEY `fk_english-definitions_idx` (`Terms_id`),
KEY `endefix` (`endef`),
CONSTRAINT `fk_english-definitions` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `enterms` (
`enterms_id` int(11) NOT NULL AUTO_INCREMENT,
`Terms_uk` varchar(128) DEFAULT NULL,
`Terms_us` varchar(128) DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`enterms_id`),
KEY `fk_enterms_1_idx` (`Terms_id`),
KEY `ukterm` (`Terms_uk`),
KEY `usterm` (`Terms_us`),
CONSTRAINT `fk_enterms_1` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `frdef` (
`frdef_id` int(11) NOT NULL AUTO_INCREMENT,
`frdef` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`frdef_id`),
KEY `fk_french-definitions_idx` (`Terms_id`),
KEY `frdefix` (`frdef`),
CONSTRAINT `fk_french-definitions` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `frterms` (
`frterms_id` int(11) NOT NULL AUTO_INCREMENT,
`Terms_fr` varchar(128) DEFAULT NULL,
`Terms_id` int(11) DEFAULT NULL,
PRIMARY KEY (`frterms_id`),
KEY `fk_frterms_idx` (`Terms_id`),
KEY `frterm` (`Terms_fr`),
CONSTRAINT `fk_frterms` FOREIGN KEY (`Terms_id`) REFERENCES `determs` (`Terms_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `frterms`
--
LOCK TABLES `frterms` WRITE;
/*!40000 ALTER TABLE `frterms` DISABLE KEYS */;
INSERT INTO `frterms` VALUES (1,'Contrat de mariage',1),(3,'Extrait du casier judiciaire',4),(4,'Registre des marriages',2);
/*!40000 ALTER TABLE `frterms` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-12-20 16:50:28
参考:https://mvnrepository.com/artifact/com.databricks/spark-xml_2.11/0.4.1