show dbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flattenDataFrame(df: DataFrame): DataFrame = { | |
val fields = df.schema.fields | |
val fieldNames = fields.map(x => x.name) | |
for (i <- fields.indices) { | |
val field = fields(i) | |
val fieldType = field.dataType | |
val fieldName = field.name | |
fieldType match { | |
case _: ArrayType => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark.sql.types import * | |
from pyspark.sql.functions import * | |
#Flatten array of structs and structs | |
def flatten(df): | |
# compute Complex Fields (Lists and Structs) in Schema | |
complex_fields = dict([(field.name, field.dataType) | |
for field in df.schema.fields | |
if type(field.dataType) == ArrayType or type(field.dataType) == StructType]) | |
while len(complex_fields)!=0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from pymongo import MongoClient | |
client = MongoClient("mongodb://localhost:27017") | |
db = client.database_Name | |
collection_conn = db['collection_name'] | |
collection_cursor = collection_conn.find() | |
collection_pandas_df = pd.DataFrame(list(collection_cursor)) |