Search in sources :

Example 1 with GcsFilesetSpec

use of com.google.cloud.datacatalog.v1beta1.GcsFilesetSpec in project beam by apache.

the class GcsTableFactory method tableBuilder.

/**
 * Creates a Beam SQL table description from a GCS fileset entry.
 */
@Override
public Optional<Table.Builder> tableBuilder(Entry entry) {
    if (!entry.hasGcsFilesetSpec()) {
        return Optional.empty();
    }
    GcsFilesetSpec gcsFilesetSpec = entry.getGcsFilesetSpec();
    List<String> filePatterns = gcsFilesetSpec.getFilePatternsList();
    // We support exactly one 'file_patterns' field and nothing else at the moment
    if (filePatterns.size() != 1) {
        throw new UnsupportedOperationException("Unable to parse GCS entry '" + entry.getName() + "'");
    }
    String filePattern = filePatterns.get(0);
    if (!filePattern.startsWith("gs://")) {
        throw new UnsupportedOperationException("Unsupported file pattern. " + "Only file patterns with 'gs://' schema are supported at the moment.");
    }
    return Optional.of(Table.builder().type("text").location(filePattern).properties(new JSONObject()).comment(""));
}
Also used : GcsFilesetSpec(com.google.cloud.datacatalog.v1beta1.GcsFilesetSpec) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 GcsFilesetSpec (com.google.cloud.datacatalog.v1beta1.GcsFilesetSpec)1