use of co.cask.cdap.hive.datasets.DatasetStorageHandler in project cdap by caskdata.
the class ExploreTableManager method generateCreateStatementFromSchemaProperty.
/**
* Generate a create statement from the "schema" property of the dataset (specification). This is used for
* Table, ObjectMappedTable and RecordScannables with record type StructuredRecord, all of which use the
* {@link DatasetStorageHandler}.
*
* @param spec the dataset specification
* @param datasetId the dataset id
* @param serdeProperties properties to be passed to the {@link co.cask.cdap.hive.datasets.DatasetSerDe}
* @param shouldErrorOnMissingSchema whether the schema is required.
* @return a CREATE TABLE statement, or null if the dataset is not explorable
* @throws UnsupportedTypeException if the schema cannot be represented in Hive
* @throws IllegalArgumentException if the schema cannot be parsed, or if shouldErrorOnMissingSchema is true and
* the dataset spec does not contain a schema.
*/
@Nullable
private String generateCreateStatementFromSchemaProperty(DatasetSpecification spec, DatasetId datasetId, String tableName, Map<String, String> serdeProperties, boolean shouldErrorOnMissingSchema) throws UnsupportedTypeException {
Schema schema = getSchemaFromProperty(spec, datasetId, shouldErrorOnMissingSchema);
if (schema == null) {
return null;
}
String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties());
return new CreateStatementBuilder(datasetId.getDataset(), databaseName, tableName, shouldEscapeColumns).setSchema(schema).setTableComment("CDAP Dataset").buildWithStorageHandler(DatasetStorageHandler.class.getName(), serdeProperties);
}
Aggregations