1

I'm trying to split a GridDB database into two tables. The first half is about 80% of the whole table while the other half is just about 20%. The code must output two tables and the names of the new tables must be derived from the single old table.

For example, If the old table was Beach Tourists, the new tables would be "Beach Tourists 1" and "Beach Tourists 2", like so. Is there a way I can do that

#...
factory = griddb.StoreFactory.get_instance()

# Initializing the container
try:
    gridstore = factory.get_store(host="127.0.0.1", port=8000, 
            cluster_name="Tourists", username="root", 
            password="") # You still don't need the password, do you?
    conInfo = griddb.ContainerInfo("Beach Tourists",
                    [
                     ["First Name", griddb.Type.STRING],
                     ["Last Name", griddb.Type.STRING],
                     ["Email Address", griddb.Type.STRING],
                     ["Time of Arrival", griddb.Type.TIMESTAMP],
                     ["Time of Departure", griddb.Type.TIMESTAMP],
                     ["Time Spent", griddb.Type.FLOAT], # In hours
                     ["Country", griddb.Type.STRING],
                    ],
                    griddb.ContainerType.COLLECTION, True)

    global con # Declaring `con` as a global variable
    con = gridstore.put_container(conInfo)   

    # Reading the first database into a Pandas DataFrame
    df = pd.read_csv("september21_beach_tourists.csv")

    # Adding the database
    for i in range(len(df)):
        ret = con.put(df.iloc[i, :])
    print("I have successfully added the data!!! Yay!")
    sql_query = pd.read_sql_query(sql_statement, con)

except Exception as e:
    print("I have not successfully added the data, no yay!")
    print("Error", e)

def splitDatabase(container):
    filename1 = "Beach Tourists 1"
    filename2 = "Beach Tourists 2"
    # Code to split database goes here...

# Calling the function with the container
splitDatabase(con)

0 Answers0