当前位置:网站首页>Mongodb meets spark (for integration)
Mongodb meets spark (for integration)
2022-07-07 13:12:00 【cui_ yonghua】
The basic chapter ( Can solve the problem of 80% The problem of ):
MongoDB data type 、 Key concepts and shell Commonly used instructions
MongoDB Various additions to documents 、 to update 、 Delete operation summary
Advanced :
Other :
One . And HDFS comparison ,MongoDB The advantages of
1、 In terms of storage mode ,HDFS In documents , The size of each file is 64M~128M, and mongo The performance is more fine grained ;
2、MongoDB Support HDFS There is no index concept , So it is faster in reading speed ;
3、MongoDB It is easier to modify data ;
4、HDFS The response level is minutes , and MongoDB The response category is milliseconds ;
5、 You can use MongoDB Powerful Aggregate Function for data filtering or preprocessing ;
6、 If you use MongoDB, There is no need to be like the traditional mode , To Redis After memory database calculation , Then save it to HDFS On .
Two . Hierarchical architecture of big data
MongoDB Can replace HDFS, As the core part of big data platform , It can be layered as follows :
The first 1 layer :MongoDB perhaps HDFS;
The first 2 layer : Resource management Such as YARN、Mesos、K8S;
The first 3 layer : Calculation engine Such as MapReduce、Spark;
The first 4 layer : Program interface Such as Pig、Hive、Spark SQL、Spark Streaming、Data Frame etc.
Reference resources :
mongo-python-driver: https://github.com/mongodb/mongo-python-driver/
Official documents :https://www.mongodb.com/docs/spark-connector/current/
3、 ... and . The source code is introduced
mongo-spark/examples/src/test/python/introduction.py
# -*- coding: UTF-8 -*-
#
# Copyright 2016 MongoDB, Inc.
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# To run this example use:
# ./bin/spark-submit --master "local[4]" \
# --conf "spark.mongodb.input.uri=mongodb://127.0.0.1/test.coll?readPreference=primaryPreferred" \
# --conf "spark.mongodb.output.uri=mongodb://127.0.0.1/test.coll" \
# --packages org.mongodb.spark:mongo-spark-connector_2.11:2.0.0 \
# introduction.py
from pyspark.sql import SparkSession
if __name__ == "__main__":
spark = SparkSession.builder.appName("Python Spark SQL basic example").getOrCreate()
logger = spark._jvm.org.apache.log4j
logger.LogManager.getRootLogger().setLevel(logger.Level.FATAL)
# Save some data
characters = spark.createDataFrame([("Bilbo Baggins", 50), ("Gandalf", 1000), ("Thorin", 195), ("Balin", 178), ("Kili", 77), ("Dwalin", 169), ("Oin", 167), ("Gloin", 158), ("Fili", 82), ("Bombur", None)], ["name", "age"])
characters.write.format("com.mongodb.spark.sql").mode("overwrite").save()
# print the schema
print("Schema:")
characters.printSchema()
# read from MongoDB collection
df = spark.read.format("com.mongodb.spark.sql").load()
# SQL
df.registerTempTable("temp")
centenarians = spark.sql("SELECT name, age FROM temp WHERE age >= 100")
print("Centenarians:")
centenarians.show()
边栏推荐
- Blog recommendation | Apache pulsar cross regional replication scheme selection practice
- 环境配置篇
- MongoDB 分片总结
- 高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
- Initialization script
- Vscade editor esp32 header file wavy line does not jump completely solved
- What are the benefits of ip2long?
- MATLAB中polarscatter函数使用
- 记一次 .NET 某新能源系统 线程疯涨 分析
- Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
猜你喜欢
[learning notes] agc010
Ogre入门尝鲜
Lingyunguang of Dachen and Xiaomi investment is listed: the market value is 15.3 billion, and the machine is implanted into the eyes and brain
OSI 七层模型
PACP学习笔记一:使用 PCAP 编程
JS缓动动画原理教学(超细节)
Analysis of DHCP dynamic host setting protocol
Sequoia China completed the new phase of $9billion fund raising
About the problem of APP flash back after appium starts the app - (solved)
MySQL master-slave replication
随机推荐
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
regular expression
详细介绍六种开源协议(程序员须知)
自定义线程池拒绝策略
MongoDB命令汇总
Layer pop-up layer closing problem
如何让electorn打开的新窗口在window任务栏上面
Common text processing tools
Initialization script
OSI 七层模型
信号强度(RSSI)知识整理
线程池拒绝策略最佳实践
飞桨EasyDL实操范例:工业零件划痕自动识别
【无标题】
Users, groups, and permissions
JS判断一个对象是否为空
TPG x AIDU|AI领军人才招募计划进行中!
高端了8年,雅迪如今怎么样?
[untitled]
货物摆放问题