Below is the code I'm using to create the table, and it's working perfectly. But the problem is with the owner of the table.
Assume John is the user who is running the Java code, and also I set the owner to Ali as shown below. However, when I checked the metastore info after the table was created, I got John was the "owner", and "Ali" was also an owner but inside the "parameter" key, which I don't think has anything to do with the owner.
So, How do I set the owner of the table to "Ali" (it's hardcoded for now, but later it'll be updated by the subject of the request)?
consider the below:
API: Java Iceberg
Metastore: Hive
HashMap<String, String> properties = new HashMap<>();
properties.put("owner", "Ali");
catalog.createTable(
identifier,
getTableSchema(),
null,
getTableLocation(),
properties
);
output
Metastore Detailed Info
{
"tableName": "employee_test",
"databaseName": "employee",
"owner": "John",
....
"sd": {
"cols": [
{
"name": "name",
"type": "string",
"comment": null
},
{
"name": "age",
"type": "int",
"comment": null
}
],
"location": "path/to/location",
"inputFormat": "org.apache.hadoop.mapred.FileInputFormat",
"outputFormat": "org.apache.hadoop.mapred.FileOutputFormat",
"serdeInfo": {
...
},
"parameters": {},
"skewedInfo": {
"skewedColNames": [],
"skewedColValues": [],
"skewedColValueLocationMaps": {}
},
"storedAsSubDirectories": false
},
"partitionKeys": [],
"parameters": {
"owner": "Ali",
"totalSize": "3773",
....
},
...
}
Here is how I solved it finally!
The hive catalog API looks like the below, of course, there are a bunch of methods but I only want to show you the public attributes, especially HMS_TABLE_OWNER.
public class HiveCatalog extends BaseMetastoreCatalog implements SupportsNamespaces, Configurable {
public static final String LIST_ALL_TABLES = "list-all-tables";
public static final String LIST_ALL_TABLES_DEFAULT = "false";
public static final String HMS_TABLE_OWNER = "hive.metastore.table.owner";
public static final String HMS_DB_OWNER = "hive.metastore.database.owner";
public static final String HMS_DB_OWNER_TYPE = "hive.metastore.database.owner-type";
private static final Logger LOG = LoggerFactory.getLogger(HiveCatalog.class);
....
}
To solve the above question, I just made a small change to my code. I changed the key owner to HiveCatalog.HMS_TABLE_OWNER. So, it will be like this
HashMap<String, String> properties = new HashMap<>();
properties.put(HiveCatalog.HMS_TABLE_OWNER, "Ali");
catalog.createTable(identifier,
tableSchema,
null,
tableLocation,
properties
);