Upload a File

In MindsDB, files are treated as tables. These are stored in the default files database. To upload a file, you must save this files database into a variable and then run the createTable() function on it.

Check out Tablesaw Docs. It allows creating tables from csv, json, and other formats. Its Pandas alternative in Java.

Note that the trailing whitespaces on column names are erased upon uploading a file to MindsDB.

Example

package org.example;

import mindsdb.MindsDB;
import mindsdb.models.Database;
import mindsdb.models.MDBTable;
import mindsdb.services.Server;
import tech.tablesaw.api.*;

public class Main {

    public static void main(String[] args) {
        Server server = MindsDB.connect();
        Database filesDB = server.getDatabase("files");
        Table userTable = Table.create().addColumns(
                StringColumn.create("name", "Alice", "Bob", "Charlie"),
                IntColumn.create("age", 25, 30, 35),
                BooleanColumn.create("is_student", true, false, true)
        );

        MDBTable userMDBTable = filesDB.createTable("users", userTable, false);
        System.out.println(userMDBTable.fetch());
    }
}

Output

Updated on