• spark读写mysql


    * 获取 Mysql 表的数据
    *
    * @param sqlContext
    * @param tableName 读取Mysql表的名字
    * @param proPath 配置文件的路径
    * @return 返回 Mysql 表的 DataFrame
    */
    def readMysqlTable(sqlContext: SQLContext, tableName: String, proPath: String) = {
    val properties: Properties = getProPerties(proPath)
    sqlContext
    .read
    .format("jdbc")
    .option("url", properties.getProperty("mysql.url"))
    .option("driver", properties.getProperty("mysql.driver"))
    .option("user", properties.getProperty("mysql.username"))
    .option("password", properties.getProperty("mysql.password"))
    // .option("dbtable", tableName.toUpperCase)
    .option("dbtable", tableName)
    .load()

    }

    /**
    * 获取 Mysql 表的数据 添加过滤条件
    *
    * @param sqlContext
    * @param table 读取Mysql表的名字
    * @param filterCondition 过滤条件
    * @param proPath 配置文件的路径
    * @return 返回 Mysql 表的 DataFrame
    */
    def readMysqlTable(sqlContext: SQLContext, table: String, filterCondition: String, proPath: String) = {
    val properties: Properties = getProPerties(proPath)
    var tableName = ""
    tableName = "(select * from " + table + " where " + filterCondition + " ) as t1"
    sqlContext
    .read
    .format("jdbc")
    .option("url", properties.getProperty("mysql.url"))
    .option("driver", properties.getProperty("mysql.driver"))
    .option("user", properties.getProperty("mysql.username"))
    .option("password", properties.getProperty("mysql.password"))
    .option("dbtable", tableName)
    .load()
    }

  • 相关阅读:
    从外部访问 Template (模板)的控件、获取它的属性值
    继续聊WPF——动态数据模板
    WPF数据模板样式选择器
    深入理解正则表达式
    nssm使用,安装服务、删除服务
    Windows删除某服务
    nssm设置solr开机启动服务
    Windows下直接双击可执行的jar
    Unsupported major.minor version 52.0——解决
    js延迟2秒执行事件
  • 原文地址:https://www.cnblogs.com/muyue123/p/14047034.html
Copyright © 2020-2023  润新知