Class SparkDB


public class SparkDB extends Object
  • Field Details

    • Mapper

      public HashMap<String,SparkDB.HMList> Mapper
      Maps column name with a list of corrisponding values
    • Headers

      public ArrayList<String> Headers
      column names
    • num_queries

      public int num_queries
      Number of entries (excluding the column name row)
    • num_header

      public int num_header
      Number of columns
  • Constructor Details

    • SparkDB

      public SparkDB()
  • Method Details

    • create

      public void create(ArrayList<String> headers) throws Exception
      Create a database in memory
      Parameters:
      headers - every element is the header name
      Throws:
      Exception
    • readFromFile

      public void readFromFile(String filename, String Crypt_Key) throws Exception
      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

      public void readFromFile(String filename) throws Exception
      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

      public void readFromString(String data) throws Exception
      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

      public ArrayList<Integer> getIDs(HashMap<String,String> in, int iter)
      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 Value
      iter - How many indices should the function return
      Returns:
      ArrayList with all IDs applying rules passed in HashMap argument
    • getIDs

      public ArrayList<Integer> getIDs(HashMap<String,String> in)
      See getIDs(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

      public ArrayList<String> get(HashMap<String,String> input, String ColToFind, int iter)
      Gets column values from of a certain column name for rows that apply certain rules. See getIDs(HashMap, int).
      Parameters:
      input - Rules in form of Key:Column name and Value:Column Value
      ColToFind - Target column name
      iter - How many indices should the function return
      Returns:
      Column values of certain rows that apply certain rows
    • get

      public ArrayList<String> get(HashMap<String,String> input, String ColToFind)
      See get(HashMap, String, int). Grab maximum indices possible.
      Parameters:
      input - Rules in form of Key:Column name and Value:Column Value
      ColToFind - Target column name
      Returns:
      Column values of certain rows that apply certain rows
    • get

      public HashMap<String,String> get(int index)
      Parameters:
      index - Target index
      Returns:
      The whole row in form of Key:Column name and Value:Column value
    • get

      public ArrayList<HashMap<String,String>> get(ArrayList<Integer> indices)
      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

      public SparkDB.HMList getColumn(String column)
      Gets a whole column as a HMList.
      Parameters:
      column - Target Column name
      Returns:
      HMList that has all the column values
    • delete

      public void delete(HashMap<String,String> input, int iter)
      Delete certain rows that apply certain rules. See getIDs(HashMap, int)
      Parameters:
      input - Rules in form of Key:Column name and Value:Column Value
      iter - How many rows that apply certain rules should be removed
    • delete

      public void delete(HashMap<String,String> input)
      See delete(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

      public void add(HashMap<String,String> in)
      Adds a row. See add(ArrayList)
      Parameters:
      in - Row in form of Key: Column name and Value: Column value
    • add

      public void add(ArrayList<HashMap<String,String>> in)
      Adds multiple rows. Every element in variable 'in' is a row
      Parameters:
      in - List of rows to be added. See add(HashMap) for more details on HashMap structure
    • modify

      public void modify(HashMap<String,String> in, HashMap<String,String> edit, int iter)
      Modifies column values for a specific column name(s) for rows that apply certain rules. See getIDs(HashMap, int)
      Parameters:
      in - Rules in form of Key:Column name and Value:Column Value
      edit - Modification(s) to apply. In form of Key: Column name and Value: Column value
      iter - How many indices to modify
    • modify

      public void modify(HashMap<String,String> in, HashMap<String,String> edit)
      See modify(HashMap, HashMap, int). Modifies all rows that apply certain rules
      Parameters:
      in - Rules in form of Key:Column name and Value:Column Value
      edit - Modification(s) to apply. In form of Key: Column name and Value: Column value
    • modify

      public void modify(int index, HashMap<String,String> edit)
      Modifies a certain row based on its index value
      Parameters:
      index - Target index value
      edit - 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

      public String toString()
      Override for toString(). returns the current data structure in CSV format
      Overrides:
      toString in class Object