Class SparkDB
java.lang.Object
SparkDB
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassA bidirectional list between index value and String value -
Field Summary
FieldsModifier and TypeFieldDescriptioncolumn namesMaps column name with a list of corrisponding valuesintNumber of columnsintNumber of entries (excluding the column name row) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds multiple rows.voidAdds a row.voidCreate a database in memoryvoiddelete(int index) Delete a row based on its index valuevoidSeedelete(HashMap, int).voidDelete certain rows that apply certain rules.get(int index) Seeget(ArrayList)Gets multiple rows based on its index valueGets column values from of a certain column name for rows that apply certain rules.Gets a whole column as a HMList.SeegetIDs(HashMap, int).Get indices of the rows that apply certain rules.
HashMap argument [pass=123] will return all rows that have '123' in 'pass' columnvoidModifies a certain row based on its index valuevoidvoidModifies column values for a specific column name(s) for rows that apply certain rules.voidreadFromFile(String filename) Reads CSV data from disk, then processes it.voidreadFromFile(String filename, String Crypt_Key) Reads encrypted CSV data from disk, decrypts it, then processes it.voidreadFromString(String data) Processes CSV content into data structureintsize()Get the number of queries (size) of the databasetoString()Override for toString().
-
Field Details
-
Mapper
Maps column name with a list of corrisponding values -
Headers
column names -
num_queries
public int num_queriesNumber of entries (excluding the column name row) -
num_header
public int num_headerNumber of columns
-
-
Constructor Details
-
SparkDB
public SparkDB()
-
-
Method Details
-
create
Create a database in memory- Parameters:
headers- every element is the header name- Throws:
Exception
-
readFromFile
Reads encrypted CSV data from disk, decrypts it, then processes it.- Parameters:
filename- The filename of the CSV file. ./data.csv to point at data.csv in the current directory.Crypt_Key- The decryption key- Throws:
Exception
-
readFromFile
Reads CSV data from disk, then processes it.- Parameters:
filename- The filename of the CSV file. ./data.csv to point at data.csv in the current directory.- Throws:
Exception- See Also:
-
readFromString
Processes CSV content into data structure- Parameters:
data- The input lines. First line should be the header. New line delimiters are '\n' and '\r'.
Headers example: "username","password"
Query Example: "morad","123"
Input String Argument Example:"username","password"\n"morad","123"- Throws:
Exception
-
getIDs
Get indices of the rows that apply certain rules.
HashMap argument [pass=123] will return all rows that have '123' in 'pass' column- Parameters:
in- Rules in form of Key:Column name and Value:Column Valueiter- How many indices should the function return- Returns:
- ArrayList with all IDs applying rules passed in HashMap argument
-
getIDs
SeegetIDs(HashMap, int). Grab maximum indices possible that apply certain rules.- Parameters:
in- Rules in form of Key:Column name and Value:Column Value- Returns:
- ArrayList with all IDs applying rules passed in HashMap argument
-
get
Gets column values from of a certain column name for rows that apply certain rules. SeegetIDs(HashMap, int).- Parameters:
input- Rules in form of Key:Column name and Value:Column ValueColToFind- Target column nameiter- How many indices should the function return- Returns:
- Column values of certain rows that apply certain rows
-
get
Seeget(HashMap, String, int). Grab maximum indices possible.- Parameters:
input- Rules in form of Key:Column name and Value:Column ValueColToFind- Target column name- Returns:
- Column values of certain rows that apply certain rows
-
get
Seeget(ArrayList)- Parameters:
index- Target index- Returns:
- The whole row in form of Key:Column name and Value:Column value
-
get
Gets multiple rows based on its index value- Parameters:
indices- Target Indices- Returns:
- The rows in form of Key:Column name and Value:Column value
-
getColumn
Gets a whole column as a HMList.- Parameters:
column- Target Column name- Returns:
- HMList that has all the column values
-
delete
Delete certain rows that apply certain rules. SeegetIDs(HashMap, int)- Parameters:
input- Rules in form of Key:Column name and Value:Column Valueiter- How many rows that apply certain rules should be removed
-
delete
Seedelete(HashMap, int). Delete all rows that apply certain rules- Parameters:
input- Rules in form of Key:Column name and Value:Column Value
-
delete
public void delete(int index) Delete a row based on its index value- Parameters:
index- Target Index Value
-
add
Adds a row. Seeadd(ArrayList)- Parameters:
in- Row in form of Key: Column name and Value: Column value
-
add
Adds multiple rows. Every element in variable 'in' is a row- Parameters:
in- List of rows to be added. Seeadd(HashMap)for more details on HashMap structure
-
modify
Modifies column values for a specific column name(s) for rows that apply certain rules. SeegetIDs(HashMap, int)- Parameters:
in- Rules in form of Key:Column name and Value:Column Valueedit- Modification(s) to apply. In form of Key: Column name and Value: Column valueiter- How many indices to modify
-
modify
Seemodify(HashMap, HashMap, int). Modifies all rows that apply certain rules- Parameters:
in- Rules in form of Key:Column name and Value:Column Valueedit- Modification(s) to apply. In form of Key: Column name and Value: Column value
-
modify
Modifies a certain row based on its index value- Parameters:
index- Target index valueedit- Modification(s) to apply. In form of Key: Column name and Value: Column value
-
size
public int size()Get the number of queries (size) of the database- Returns:
- The number of queries, excluding headers
-
toString
Override for toString(). returns the current data structure in CSV format
-