好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>后端语言>PHP
<tfoot draggable='sEl'></tfoot>

关于sparksqlphp的信息

很多站长朋友们都不太清楚sparksqlphp,今天小编就来给大家整理sparksqlphp,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 如何使用 Spark SQL 2、 编程分什么语言? 3、 spark sql语法整理 4、 Spark SQL(十):Hive On Spark 5、 hive kerberos sparksql怎么创建hivecontext 如何使用 Spark SQL

一、启动方法

/data/spark-1.4.0-bin-cdh4/bin/spark-sql --master spark://master:7077 --total-executor-cores 10 --executor-memory 1g --executor-cores 2

注:/data/spark-1.4.0-bin-cdh4/为spark的安装路径

/data/spark-1.4.0-bin-cdh4/bin/spark-sql –help 查看启动选项

--master MASTER_URL 指定master url

--executor-memory MEM 每个executor的内存,默认为1G

--total-executor-cores NUM 所有executor的总核数

-e <quoted-query-string> 直接执行查询SQL

-f <filename> 以文件方式批量执行SQL

二、Spark sql对hive支持的功能

1、查询语句:SELECT GROUP BY ORDER BY CLUSTER BY SORT BY

2、hive操作运算:

1) 关系运算:= ==, <>, <, >, >=, <=

2) 算术运算:+, -, *, /, %

3) 逻辑运算:AND, , OR, ||

4) 复杂的数据结构

5) 数学函数:(sign, ln, cos, etc)

6) 字符串函数:

3、 UDF

4、 UDAF

5、 用户定义的序列化格式

6、join操作:JOIN {LEFT|RIGHT|FULL} OUTER JOIN LEFT SEMI JOIN CROSS JOIN

7、 unions操作:

8、 子查询: SELECT col FROM ( SELECT a + b AS col from t1) t2

9、Sampling

10、 Explain

11、 分区表

12、 视图

13、 hive ddl功能:CREATE TABLE、CREATE TABLE AS SELECT、ALTER TABLE

14、 支持的数据类型:TINYINT SMALLINT INT BIGINT BOOLEAN FLOAT DOUBLE STRING BINARY TIMESTAMPDATE ARRAY MAP STRUCT

三、Spark sql 在客户端编程方式进行查询数据

1、启动spark-shell

./spark-shell --master spark://master:7077 --total-executor-cores 10 --executor-memory 1g --executor-cores 2

2、编写程序

val sqlContext = new org.apache.spark.sql.SQLContext(sc)

val df = sqlContext.read.json("examples/src/main/resources/people.json")

查看所有数据:df.show()

查看表结构:df.printSchema()

只看name列:df.select("name").show()

对数据运算:df.select(df("name"), df("age") + 1).show()

过滤数据:df.filter(df("age") > 21).show()

分组统计:df.groupBy("age").count().show()

1、查询txt数据

import sqlContext.implicits._

case class Person(name: String, age: Int)

val people = sc.textFile("examples/src/main/resources/people.txt").map(_.split(",")).map(p => Person(p(0), p(1).trim.toInt)).toDF()

people.registerTempTable("people")

val teenagers = sqlContext.sql("SELECT name, age FROM people WHERE age >= 13 AND age <= 19")

2、parquet文件

val df = sqlContext.read.load("examples/src/main/resources/users.parquet")

3、hdfs文件

val df = sqlContext.read.load("hdfs://namenode.Hadoop:9000/user/hive/warehouse/spark_test.db/test_parquet/part-r-00001.gz.parquet")

4、保存查询结果数据

val df = sqlContext.read.load("examples/src/main/resources/users.parquet")

df.select("name", "favorite_color").write.save("namesAndFavColors.parquet“)

四、Spark sql性能调优

缓存数据表:sqlContext.cacheTable("tableName")

取消缓存表:sqlContext.uncacheTable("tableName")

spark.sql.inMemoryColumnarStorage测试数据pressedtrue当设置为true时,Spark SQL将为基于数据统计信息的每列自动选择一个压缩算法。

spark.sql.inMemoryColumnarStorage.batchSize10000柱状缓存的批数据大小。更大的批数据可以提高内存的利用率以及压缩效率,但有OOMs的风险

编程分什么语言?

这个问题。。。一两句说不清啊。。。。编程语言有很多,常见的有汇编、C、C++、C#、Java、VB、Delphi等等共有上百种。。。根据不同的分类方法,可以分为编译型、解释型和脚本语言,也可分为面向过程和面向对象等。

汇编:低级语言,非常底层,非常强大但非常麻烦,现在很少用汇编写东西。

C:中级语言,面向过程的编程语言,既有高级语言特点,也保留了低级语言的特点,一般作为编程入门。

C++:在C语言的基础上加入了类的概念,成为混合型面向对象语言。

C#:微软在C++基础上开发的面向对象型语言,现在很流行。。。

Java:sun 公司开发的纯面向对象型语言,分为J2EE\J2SE\J2ME三种,开发手机游戏用的就是J2ME。

VB:微软公司开发的一种解释型的计算机语言,很简单,甚至被称为玩具语言,不过现在微软不再开发VB6了,它的升级为VB.NET,彻底拜托了玩具语言这个称呼,还取消了VB6中能简单实现的控件数组。。。。不过有些地方比VB6强大。

Delphi:曾经程序员以会Delphi为荣,甚至被称为VB杀手,不过现在好像用的不多了。。

spark sql语法整理

add_months

add_months(start_date, num_months) - Returns the date that is num_months after start_date.

Examples:

cast

cast(expr AS type) - Casts the value expr to the target data type type.

Examples:

concat

concat(col1, col2, ..., colN) - Returns the concatenation of col1, col2, ..., colN.

Examples:

concat_ws

concat_ws(sep, [str | array(str)]+) - Returns the concatenation of the strings separated by sep.

Examples:

current_date

current_date() - Returns the current date at the start of query evaluation.

current_timestamp

current_timestamp() - Returns the current timestamp at the start of query evaluation.

date

date(expr) - Casts the value expr to the target data type date.

date_add

date_add(start_date, num_days) - Returns the date that is num_days after start_date.

Examples:

date_format

date_format(timestamp, fmt) - Converts timestamp to a value of string in the format specified by the date format fmt.

Examples:

date_sub

date_sub(start_date, num_days) - Returns the date that is num_days before start_date.

Examples:

datediff

datediff(endDate, startDate) - Returns the number of days from startDate to endDate.

Examples:

day

day(date) - Returns the day of month of the date/timestamp.

Examples:

dayofmonth

dayofmonth(date) - Returns the day of month of the date/timestamp.

Examples:

dayofweek

dayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).

Examples:

dayofyear

dayofyear(date) - Returns the day of year of the date/timestamp.

Examples:

explode

explode(expr) - Separates the elements of array expr into multiple rows, or the elements of map expr into multiple rows and columns.

Examples:

from_unixtime

from_unixtime(unix_time, format) - Returns unix_time in the specified format.

Examples:

if

if(expr1, expr2, expr3) - If expr1 evaluates to true, then returns expr2; otherwise returns expr3.

Examples:

left

left(str, len) - Returns the leftmost len(len can be string type) characters from the string str,if len is less or equal than 0 the result is an empty string.

Examples:

length

length(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.

Examples:

map

map(key0, value0, key1, value1, ...) - Creates a map with the given key/value pairs.

Examples:

nvl(expr1, expr2) - Returns expr2 if expr1 is null, or expr1 otherwise.

Examples:

nvl2

nvl2(expr1, expr2, expr3) - Returns expr2 if expr1 is not null, or expr3 otherwise.

Examples:

rank

rank() - Computes the rank of a value in a group of values. The result is one plus the number of rows preceding or equal to the current row in the ordering of the partition. The values will produce gaps in the sequence.

regexp_extract

regexp_extract(str, regexp[, idx]) - Extracts a group that matches regexp.

Examples:

regexp_replace

regexp_replace(str, regexp, rep) - Replaces all substrings of str that match regexp with rep.

Examples:

replace

replace(str, search[, replace]) - Replaces all occurrences of search with replace.

Arguments:

str - a string expression

search - a string expression. If search is not found in str, str is returned unchanged.

replace - a string expression. If replace is not specified or is an empty string, nothing replaces the string that is removed from str.

Examples:

row_number

row_number() - Assigns a unique, sequential number to each row, starting with one, according to the ordering of rows within the window partition.

split

split(str, regex) - Splits str around occurrences that match regex.

Examples:

substr

substr(str, pos[, len]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.

Examples:

to_date

to_date(date_str[, fmt]) - Parses the date_str expression with the fmt expression to a date. Returns null with invalid input. By default, it follows casting rules to a date if the fmt is omitted.

Examples:

to_timestamp

to_timestamp(timestamp[, fmt]) - Parses the timestamp expression with the fmt expression to a timestamp. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted.

Examples:

unix_timestamp

unix_timestamp([expr[, pattern]]) - Returns the UNIX timestamp of current or specified time.

Examples:

weekday

weekday(date) - Returns the day of the week for date/timestamp (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).

Examples:

weekofyear

weekofyear(date) - Returns the week of the year of the given date. A week is considered to start on a Monday and week 1 is the first week with >3 days.

Examples:

Spark SQL(十):Hive On Spark

Hive是目前大数据领域,事实上的SQL标准。其底层默认是基于MapReduce实现的,但是由于MapReduce速度实在比较慢,因此这几年,陆续出来了新的SQL查询引擎,包括Spark SQL,Hive On Tez,Hive On Spark等。

Spark SQL与Hive On Spark是不一样的。Spark SQL是Spark自己研发出来的针对各种数据源,包括Hive、JSON、Parquet、JDBC、RDD等都可以执行查询的,一套基于Spark计算引擎的查询引擎。因此它是Spark的一个项目,只不过提供了针对Hive执行查询的工功能而已,适合在一些使用Spark技术栈的大数据应用类系统中使用。

而Hive On Spark,是Hive的一个项目,它是将Spark作为底层的查询引擎(不通过MapReduce作为唯一的查询引擎)。Hive On Spark,只适用于Hive,在可预见的未来,很有可能Hive默认的底层引擎就从MapReduce切换为Spark了;适合于将原有的Hive数据仓库以及数据统计分析替换为Spark引擎,作为全公司通用的大数据统计分析引擎。

Hive On Spark做了一些优化:

1、Map Join

Spark SQL默认对join是支持使用broadcast机制将小表广播到各个节点上,以进行join的。但是问题是,这会给Driver和Worker带来很大的内存开销。因为广播的数据要一直保留在Driver内存中。所以目前采取的是,类似乎MapReduce的Distributed Cache机制,即提高HDFS replica factor的复制因子,以让数据在每个计算节点上都有一个备份,从而可以在本地进行数据读取。

2、Cache Table

对于某些需要对一张表执行多次操作的场景,Hive On Spark内部做了优化,即将要多次操作的表cache到内存中,以便于提升性能。但是这里要注意,并不是对所有的情况都会自动进行cache。所以说,Hive On Spark还有很多不完善的地方。

Hive QL语句 =>

语法分析 => AST =>

生成逻辑执行计划 => Operator Tree =>

优化逻辑执行计划 => Optimized Operator Tree =>

生成物理执行计划 => Task Tree =>

优化物理执行计划 => Optimized Task Tree =>

执行优化后的Optimized Task Tree

hive kerberos sparksql怎么创建hivecontext

park+shark ,可以直接用hive原来的表。

phpHiveAdmin将HQL请求发送给HAproxy负载的Hive server集群。 三、phpHiveAdmin读取Metadata的数据,注意这里是只读,并不存在对Metadata的读写。因为元数据非常重要,涉及到底层数据的正确性,所以不能随意修改。

关于sparksqlphp的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于关于sparksqlphp的信息的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did197387
更新时间:2023-04-26   阅读:18次

上一篇: 运行PHP8080 运行内存

下一篇:phpalert跳转 php 跳转到指定url

相关资讯

最新资料更新

  • 1.php生成静态代码 php如何实现静态化
  • 2.包含ampquotphp的词条
  • 3.php网页老是跳转 php 网页跳转
  • 4.包含php-vcmd的词条
  • 5.php字母循序排列 php字符串排序
  • 6.phpsql添加记录 php数据表里怎么添加数据
  • 7.phpwebim开发 php web开发实用教程
  • 8.redis缓存类php php redis页面缓存
  • 9.php定义多个常量 php定义多个变量
  • 10.php河内塔问题 河内塔算法
  • 11.php从事哪个方面 php干啥的
  • 12.php重命名不了 php 命名空间 通俗易懂
  • 13.php使用嵌套for php解析嵌套json
  • 14.杭州php前景如何 杭州php培训学校
  • 15.php加密12进 php加密解密
  • 16.php合并特殊字符 php合并单元格的代码
  • 17.关于php_ssh.dll的信息
  • 18.php求数组的交集 php数组处理函数
  • 19.php技术网学习 php技术门户
  • 20.php中文注释乱码 php注释语句

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]