Search in sources :

Example 1 with DatasetStorageHandler

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);
}
Also used : DatasetStorageHandler(co.cask.cdap.hive.datasets.DatasetStorageHandler) Schema(co.cask.cdap.api.data.schema.Schema) CreateStatementBuilder(co.cask.cdap.explore.table.CreateStatementBuilder) Nullable(javax.annotation.Nullable)

Aggregations

Schema (co.cask.cdap.api.data.schema.Schema)1 CreateStatementBuilder (co.cask.cdap.explore.table.CreateStatementBuilder)1 DatasetStorageHandler (co.cask.cdap.hive.datasets.DatasetStorageHandler)1 Nullable (javax.annotation.Nullable)1