Search in sources :

Example 11 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.

the class ParquetFileLineFetcher method openReader.

@Override
public void openReader(Readable readable) {
    Path path = readable.path();
    try {
        HadoopInputFile file = HadoopInputFile.fromPath(path, this.conf);
        this.reader = ParquetFileReader.open(file);
        this.schema = this.reader.getFooter().getFileMetaData().getSchema();
        this.columnIO = new ColumnIOFactory().getColumnIO(this.schema);
    } catch (IOException e) {
        throw new LoadException("Failed to open parquet reader for '%s'", e, readable);
    }
    this.resetOffset();
}
Also used : Path(org.apache.hadoop.fs.Path) HadoopInputFile(org.apache.parquet.hadoop.util.HadoopInputFile) IOException(java.io.IOException) ColumnIOFactory(org.apache.parquet.io.ColumnIOFactory) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 12 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.

the class RowFetcher method connect.

private Connection connect() throws SQLException {
    String url = this.source.vendor().buildUrl(this.source);
    LOG.info("Connect to database {}", url);
    String driverName = this.source.driver();
    String username = this.source.username();
    String password = this.source.password();
    try {
        // Register JDBC driver
        Class.forName(driverName);
    } catch (ClassNotFoundException e) {
        throw new LoadException("Invalid driver class '%s'", e, driverName);
    }
    return DriverManager.getConnection(url, username, password);
}
Also used : LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 13 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.

the class ParquetUtil method convertObject.

public static Object convertObject(Group group, int fieldIndex) {
    Type fieldType = group.getType().getType(fieldIndex);
    if (!fieldType.isPrimitive()) {
        throw new LoadException("Unsupported rich object type %s", fieldType);
    }
    String fieldName = fieldType.getName();
    // Field is no value
    if (group.getFieldRepetitionCount(fieldName) == 0) {
        return null;
    }
    Object object;
    switch(fieldType.asPrimitiveType().getPrimitiveTypeName()) {
        case INT32:
            object = group.getInteger(fieldName, 0);
            break;
        case INT64:
            object = group.getLong(fieldName, 0);
            break;
        case INT96:
            object = dateFromInt96(group.getInt96(fieldName, 0));
            break;
        case FLOAT:
            object = group.getFloat(fieldName, 0);
            break;
        case DOUBLE:
            object = group.getDouble(fieldName, 0);
            break;
        case BOOLEAN:
            object = group.getBoolean(fieldName, 0);
            break;
        default:
            object = group.getValueToString(fieldIndex, 0);
            break;
    }
    return object;
}
Also used : Type(org.apache.parquet.schema.Type) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 14 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException in project hugegraph-computer by hugegraph.

the class LoaderFileInputSplitFetcher method scanLocalPaths.

private List<String> scanLocalPaths(FileSource source) {
    List<String> paths = new ArrayList<>();
    File file = FileUtils.getFile(source.path());
    FileFilter filter = source.filter();
    if (file.isFile()) {
        if (!filter.reserved(file.getName())) {
            throw new LoadException("Please check file name and extensions, ensure " + "that at least one file is available for reading");
        }
        paths.add(file.getAbsolutePath());
    } else {
        assert file.isDirectory();
        File[] subFiles = file.listFiles();
        if (subFiles == null) {
            throw new LoadException("Error while listing the files of " + "path '%s'", file);
        }
        for (File subFile : subFiles) {
            if (filter.reserved(subFile.getName())) {
                paths.add(subFile.getAbsolutePath());
            }
        }
    }
    return paths;
}
Also used : ArrayList(java.util.ArrayList) FileFilter(com.baidu.hugegraph.loader.source.file.FileFilter) File(java.io.File) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 15 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.

the class HugeGraphLoader method createSchema.

private void createSchema() {
    LoadOptions options = this.context.options();
    if (!StringUtils.isEmpty(options.schema)) {
        File file = FileUtils.getFile(options.schema);
        HugeClient client = this.context.client();
        GroovyExecutor groovyExecutor = new GroovyExecutor();
        groovyExecutor.bind(Constants.GROOVY_SCHEMA, client.schema());
        String script;
        try {
            script = FileUtils.readFileToString(file, Constants.CHARSET);
        } catch (IOException e) {
            throw new LoadException("Failed to read schema file '%s'", e, options.schema);
        }
        groovyExecutor.execute(script, client);
    }
    this.context.updateSchemaCache();
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) IOException(java.io.IOException) File(java.io.File) GroovyExecutor(com.baidu.hugegraph.loader.executor.GroovyExecutor) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Aggregations

LoadException (com.baidu.hugegraph.loader.exception.LoadException)32 IOException (java.io.IOException)18 File (java.io.File)10 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 FileFilter (com.baidu.hugegraph.loader.source.file.FileFilter)3 Path (org.apache.hadoop.fs.Path)3 ServerException (com.baidu.hugegraph.exception.ServerException)2 InitException (com.baidu.hugegraph.loader.exception.InitException)2 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)2 LoadSummary (com.baidu.hugegraph.loader.metrics.LoadSummary)2 Readable (com.baidu.hugegraph.loader.reader.Readable)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 CompressorInputStream (org.apache.commons.compress.compressors.CompressorInputStream)2 CompressionInputStream (org.apache.hadoop.io.compress.CompressionInputStream)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 HugeClientBuilder (com.baidu.hugegraph.driver.HugeClientBuilder)1 GroovyExecutor (com.baidu.hugegraph.loader.executor.GroovyExecutor)1 InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)1