当前位置: 首页 > news >正文

Spark SQL----DISTRIBUTE BY子句

Spark SQL----DISTRIBUTE BY子句

  • 一、描述
  • 二、语法
  • 三、参数
  • 四、例子

一、描述

DISTRIBUTE BY子句用于根据输入表达式对数据进行重新分区。与CLUSTER BY子句不同,这不会对每个分区内的数据进行排序。

二、语法

DISTRIBUTE BY { expression [ , ... ] }

三、参数

  • expression
    指定产生由一个或多个值、运算符和SQL函数组成的组合。

四、例子

CREATE TABLE person (name STRING, age INT);
INSERT INTO person VALUES('Zen Hui', 25),('Anil B', 18),('Shone S', 16),('Mike A', 25),('John A', 18),('Jack N', 16);-- Reduce the number of shuffle partitions to 2 to illustrate the behavior of `DISTRIBUTE BY`.
-- It's easier to see the clustering and sorting behavior with less number of partitions.
SET spark.sql.shuffle.partitions = 2;-- Select the rows with no ordering. Please note that without any sort directive, the result
-- of the query is not deterministic. It's included here to just contrast it with the
-- behavior of `DISTRIBUTE BY`. The query below produces rows where age columns are not
-- clustered together.
SELECT age, name FROM person;
+---+-------+
|age|   name|
+---+-------+
| 16|Shone S|
| 25|Zen Hui|
| 16| Jack N|
| 25| Mike A|
| 18| John A|
| 18| Anil B|
+---+-------+-- Produces rows clustered by age. Persons with same age are clustered together.
-- Unlike `CLUSTER BY` clause, the rows are not sorted within a partition.
SELECT age, name FROM person DISTRIBUTE BY age;
+---+-------+
|age|   name|
+---+-------+
| 25|Zen Hui|
| 25| Mike A|
| 18| John A|
| 18| Anil B|
| 16|Shone S|
| 16| Jack N|
+---+-------+
http://www.lryc.cn/news/406418.html

相关文章:

  • HTML5-canvas1
  • 【NOI-题解】1009 - 数组逆序1162 - 数组元素的删除1211 - 数组元素的插入1161. 元素插入有序数组1159. 数组元素的移动
  • 新电脑如何设置 npm 源及查看源、安装 cnpm、pnpm 和 yarn 的详细教程
  • 完全移动huggingface模型仓库(不是简单mv)
  • 手机空号过滤批量查询的意义及方法
  • Dockerfile制作部署wordpress-6.6
  • 项目的纪要
  • ubuntu 更新源
  • XGBoost、RF随机森林算法MATLAB实现
  • WPF 解决: DataGrid 已定义列,但是还是会显示模型的所有属性的问题
  • 【ai】Easy-RAG : ImportError: cannot import name ‘BaseModel‘ from ‘pydantic‘
  • WebKit简介
  • 笔记 | Python环境下的GUI编程常用包
  • mysql 数据库空间统计sql
  • 【Linux】线程——线程池、线程池的实现、线程安全的线程池、单例模式的概念、饿汉和懒汉模式、互斥锁、条件变量、信号量、自旋锁、读写锁
  • stm32入门-----TIM定时器(PWM输出比较——下)
  • css实现线条中间高亮,左右两边模糊(linear-gradient的运用)
  • 【数据结构】建堆算法复杂度分析及TOP-K问题
  • Thinkphp5实现前后端通过接口通讯基本操作方法
  • Go 语言任务编排 WaitGroup
  • 星环科技推出知识库产品 AI PC时代数据交互方式变革
  • 10道JVM经典面试题
  • Redisson常用的数据结构及应用场景
  • 【实现100个unity特效之8】使用ShaderGraph实现2d贴图中指定部分局部发光效果
  • Ubuntu 24.04 LTS Noble安装Docker Desktop简单教程
  • XML 和 SimpleXML 入门教程
  • leetcode--链表类题目总结
  • 打卡第22天------回溯算法
  • Ubuntu对比两个文件内容有什么区别?
  • python:本机摄像头目标检测实时推理(使用YOLOv8n模型)