parquet

Spark学习之路(十)―― Spark SQL 外部数据源

匿名 (未验证) 提交于 2019-12-02 23:38:02
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37809146/article/details/91281766 一、简介 1.1 多数据源支持 Spark支持以下六个核心数据源,同时Spark社区还提供了多达上百种数据源的读取方式,能够满足绝大部分使用场景。 CSV JSON Parquet ORC JDBC/ODBC connections Plain-text files 注:以下所有测试文件均可从本仓库的 resources 目录进行下载 1.2 读数据格式 所有读取API遵循以下调用格式: // 格式 DataFrameReader.format(...).option("key", "value").schema(...).load() // 示例 spark.read.format("csv") .option("mode", "FAILFAST") // 读取模式 .option("inferSchema", "true") // 是否自动推断schema .option("path", "path/to/file(s)") // 文件路径 .schema(someSchema) // 使用预定义的schema .load() 读取模式有以下三种可选项: 读模式 描述 permissive 当遇到损坏的记录时

How to deal with tasks running too long (comparing to others in job) in yarn-client?

故事扮演 提交于 2019-12-02 23:18:49
We use a Spark cluster as yarn-client to calculate several business, but sometimes we have a task run too long time: We don't set timeout but I think default timeout a spark task is not too long such here ( 1.7h ). Anyone give me an ideal to work around this issue ??? There is no way for spark to kill its tasks if its taking too long. But I figured out a way to handle this using speculation , This means if one or more tasks are running slowly in a stage, they will be re-launched. spark.speculation true spark.speculation.multiplier 2 spark.speculation.quantile 0 Note: spark.speculation.quantile

Append new data to partitioned parquet files

血红的双手。 提交于 2019-12-02 20:49:09
I am writing an ETL process where I will need to read hourly log files, partition the data, and save it. I am using Spark (in Databricks). The log files are CSV so I read them and apply a schema, then perform my transformations. My problem is, how can I save each hour's data as a parquet format but append to the existing data set? When saving, I need to partition by 4 columns present in the dataframe. Here is my save line: data .filter(validPartnerIds($"partnerID")) .write .partitionBy("partnerID","year","month","day") .parquet(saveDestination) The problem is that if the destination folder

Inspect Parquet from command line

♀尐吖头ヾ 提交于 2019-12-02 20:09:28
How do I inspect the content of a Parquet file from the command line? The only option I see now is $ hadoop fs -get my-path local-file $ parquet-tools head local-file | less I would like to avoid creating the local-file and view the file content as json rather than the typeless text that parquet-tools prints. Is there an easy way? fembot I recommend just building and running the parquet-tools.jar for your Hadoop distribution. Checkout the github project: https://github.com/apache/parquet-mr/tree/master/parquet-tools hadoop jar ./parquet-tools-<VERSION>.jar <command> . gil.fernandes You can use

Spark 2.0 deprecates 'DirectParquetOutputCommitter', how to live without it?

一世执手 提交于 2019-12-02 17:39:31
Recently we migrated from "EMR on HDFS" --> "EMR on S3" (EMRFS with consistent view enabled) and we realized the Spark 'SaveAsTable' (parquet format) writes to S3 were ~4x slower as compared to HDFS but we found a workaround of using the DirectParquetOutputCommitter -[1] w/ Spark 1.6. Reason for S3 slowness - We had to pay the so called Parquet tax-[2] where the default output committer writes to a temporary table and renames it later where the rename operation in S3 is very expensive Also we do understand the risk of using 'DirectParquetOutputCommitter' which is possibility of data corruption

How to read a nested collection in Spark

做~自己de王妃 提交于 2019-12-02 17:38:21
I have a parquet table with one of the columns being , array<struct<col1,col2,..colN>> Can run queries against this table in Hive using LATERAL VIEW syntax. How to read this table into an RDD, and more importantly how to filter, map etc this nested collection in Spark? Could not find any references to this in Spark documentation. Thanks in advance for any information! ps. Felt might be helpful to give some stats on the table. Number of columns in main table ~600. Number of rows ~200m. Number of "columns" in nested collection ~10. Avg number of records in nested collection ~35. There is no

Spark SQL 笔记

老子叫甜甜 提交于 2019-12-02 16:46:39
Spark SQL 简介 SparkSQL 的前身是 Shark, SparkSQL 产生的根本原因是其完全脱离了 Hive 的限制。(Shark 底层依赖于 Hive 的解析器, 查询优化器) SparkSQL 支持查询原生的 RDD。 能够在 scala/java 中写 SQL 语句。 支持简单的 SQL 语法检查, 能够在 Scala 中 写Hive 语句访问 Hive 数据, 并将结果取回作为RDD使用 Spark on Hive 和 Hive on Spark Spark on Hive: Hive 只作为储存角色, Spark负责 sql 解析优化, 执行。 Hive on Spark: Hive 即作为存储又负责 sql 的解析优化, Spark 负责执行。 Dataset 与 DataFrame Dataset 是一个分布式数据容器,与 RDD 类似, 然而 DataSet 更像 传统数据库的二维表格, 除了数据以外, 还掌握的结构信息, 即schema。 同时, 与 Hive 类似, Dataset 也支持嵌套数据类型 (struct、array 和 map)。 从 API 易用性角度上看, DataSet API 提供的是一套高层的关系操作, 比函数式的 RDD API 更加友好, 门槛更低。 Dataset 的底层封装的是RDD, 当 RDD 的泛型是 Row

Parquet vs ORC vs ORC with Snappy

心不动则不痛 提交于 2019-12-02 13:50:52
I am running a few tests on the storage formats available with Hive and using Parquet and ORC as major options. I included ORC once with default compression and once with Snappy. I have read many a documents that state Parquet to be better in time/space complexity as compared to ORC but my tests are opposite to the documents I went through. Follows some details of my data. Table A- Text File Format- 2.5GB Table B - ORC - 652MB Table C - ORC with Snappy - 802MB Table D - Parquet - 1.9 GB Parquet was worst as far as compression for my table is concerned. My tests with the above tables yielded

How to efficiently read multiple small parquet files with Spark? is there a CombineParquetInputFormat?

别等时光非礼了梦想. 提交于 2019-12-02 08:19:20
Spark generated multiple small parquet Files. How can one handle efficiently small number of parquet files both on producer and consumer Spark jobs. The most straightforward approach IMHO is to use repartition/coalesce (prefer coalesce unless data is skewed and you want to create same-sized outputs) before writing parquet files so that you will not create small files to begin with. df .map(<some transformation>) .filter(<some filter>) ///... .coalesce(<number of partitions>) .write .parquet(<path>) Number of partitions could be calculated on count of total rows in dataframe divided by some

Is it possible to load parquet table directly from file?

岁酱吖の 提交于 2019-12-02 04:47:43
问题 If I have a binary data file(it can be converted to csv format), Is there any way to load parquet table directly from it? Many tutorials show loading csv file to text table, and then from text table to parquet table. From efficiency point of view, is it possible to load parquet table directly from either a binary file like what I already have? Ideally using create external table command. Or I need to convert it to csv file first? Is there any file format restriction? 回答1: Unfortunately it is