微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将文件导入为RDD与DF之间的区别

如何解决将文件导入为RDD与DF之间的区别

我对在Spark中导入数据感到困惑。 我们可以使用RDD在spark中导入文件,然后将其转换为DF,然后注册为表,然后在其上使用sql。 但是我们也可以直接使用sqlContext将数据作为DF导入,以上两种方法有什么区别?

解决方法

可以以数据帧格式加载数据。

根据自身Spark documentation

DataFrame是组织为命名列的数据集。它是 概念上等效于关系数据库中的表或数据 R / Python中的框架,但在后台进行了更丰富的优化。 DataFrame可以从多种来源构建,例如: 结构化数据文件,Hive中的表,外部数据库或现有 RDD。 DataFrame API在Scala,Java,Python和R中可用。 在Scala和Java中,DataFrame由行的数据集表示。在 在Scala API中,DataFrame只是Dataset [Row]的类型别名。 而在Java API中,用户需要使用数据集来表示 数据框。

例如,如何以文本框加载文本文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
    
    <context:component-scan base-package="com.myproject.business.service.impl" />
    <context:component-scan base-package="com.myproject.encryption" />

    <!-- other services are skipped -->

    <bean id="encryptionService" parent="txnProxyTemplate">
        <property name="target">
            <bean class="com.myproject.business.service.impl.EncryptionServiceImpl">
                <property name="apiVaultClient" ref="apiVaultClient" />
            </bean>
        </property>
    </bean>
    </beans>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。