Search in sources :

Example 1 with FileSystemFactory

use of com.qlangtech.tis.offline.FileSystemFactory in project plugins by qlangtech.

the class TestDataXHudiWriter method createDataXWriter.

private static HudiTest createDataXWriter(Optional<FileSystemFactory> fsFactory) {
    final DefaultSparkConnGetter sparkConnGetter = new DefaultSparkConnGetter();
    sparkConnGetter.name = "default";
    sparkConnGetter.master = "spark://sparkmaster:7077";
    DataXHudiWriter writer = new DataXHudiWriter() {

        @Override
        public Class<?> getOwnerClass() {
            return DataXHudiWriter.class;
        }

        @Override
        public IHiveConnGetter getHiveConnMeta() {
            return HdfsFileSystemFactoryTestUtils.createHiveConnGetter();
        }

        @Override
        public ISparkConnGetter getSparkConnGetter() {
            return sparkConnGetter;
        }

        @Override
        public FileSystemFactory getFs() {
            return fsFactory.isPresent() ? fsFactory.get() : HdfsFileSystemFactoryTestUtils.getFileSystemFactory();
        }
    };
    writer.template = DataXHudiWriter.getDftTemplate();
    writer.fsName = HdfsFileSystemFactoryTestUtils.FS_NAME;
    writer.setKey(new KeyedPluginStore.Key(null, HdfsFileSystemFactoryTestUtils.testDataXName.getName(), null));
    writer.tabType = HudiWriteTabType.COW.getValue();
    writer.batchOp = BatchOpMode.BULK_INSERT.getValue();
    writer.shuffleParallelism = 3;
    writer.partitionedBy = "pt";
    // writer.batchByteSize = 3456;
    // writer.batchSize = 9527;
    // writer.dbName = dbName;
    writer.writeMode = "insert";
    // writer.autoCreateTable = true;
    // writer.postSql = "drop table @table";
    // writer.preSql = "drop table @table";
    // writer.dataXName = HdfsFileSystemFactoryTestUtils.testDataXName.getName();
    // writer.dbName = dbName;
    // HudiSelectedTab hudiTab = new HudiSelectedTab() {
    // @Override
    // public List<ColMeta> getCols() {
    // return WriterTemplate.createColMetas();
    // }
    // };
    // //hudiTab.partitionPathField = WriterTemplate.kind;
    // hudiTab.recordField = WriterTemplate.customerregisterId;
    // hudiTab.sourceOrderingField = WriterTemplate.lastVer;
    // hudiTab.setWhere("1=1");
    // hudiTab.name = WriterTemplate.TAB_customer_order_relation;
    List<HdfsColMeta> colsMeta = HdfsColMeta.getColsMeta(Configuration.from(IOUtils.loadResourceFromClasspath(writer.getClass(), hudi_datax_writer_assert_without_optional)).getConfiguration(cfgPathParameter));
    HudiSelectedTab tab = new HudiSelectedTab() {

        @Override
        public List<ColMeta> getCols() {
            return colsMeta.stream().map((c) -> {
                ColMeta col = new ColMeta();
                col.setName(c.getName());
                col.setPk(c.pk);
                col.setType(c.type);
                col.setNullable(c.nullable);
                return col;
            }).collect(Collectors.toList());
        }
    };
    tab.name = WriterTemplate.TAB_customer_order_relation;
    tab.partition = new OffPartition();
    tab.sourceOrderingField = "last_ver";
    tab.recordField = "customerregister_id";
    return new HudiTest(writer, WriterTemplate.createCustomer_order_relationTableMap(Optional.of(tab)), tab);
}
Also used : DefaultSparkConnGetter(com.qlangtech.tis.config.spark.impl.DefaultSparkConnGetter) IExecChainContext(com.qlangtech.tis.exec.IExecChainContext) TISCollectionUtils(com.qlangtech.tis.manage.common.TISCollectionUtils) BeforeClass(org.junit.BeforeClass) HudiWriter(com.alibaba.datax.plugin.writer.hudi.HudiWriter) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) Configuration(com.alibaba.datax.common.util.Configuration) ISparkConnGetter(com.qlangtech.tis.config.spark.ISparkConnGetter) Lists(com.google.common.collect.Lists) CenterResource(com.qlangtech.tis.manage.common.CenterResource) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) HdfsPath(com.qlangtech.tis.hdfs.impl.HdfsPath) IHiveMetaStore(com.qlangtech.tis.config.hive.meta.IHiveMetaStore) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) DataxUtils(com.qlangtech.tis.offline.DataxUtils) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) ITISFileSystem(com.qlangtech.tis.fs.ITISFileSystem) OffPartition(com.qlangtech.tis.plugin.datax.hudi.partition.OffPartition) DataXCfgGenerator(com.qlangtech.tis.datax.impl.DataXCfgGenerator) HdfsFileSystemFactoryTestUtils(com.qlangtech.tis.hdfs.test.HdfsFileSystemFactoryTestUtils) IStreamIncrGenerateStrategy(com.qlangtech.tis.sql.parser.tuple.creator.IStreamIncrGenerateStrategy) IPath(com.qlangtech.tis.fs.IPath) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) FileSystemFactory(com.qlangtech.tis.offline.FileSystemFactory) File(java.io.File) HdfsColMeta(com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta) IParamContext(com.qlangtech.tis.order.center.IParamContext) List(java.util.List) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Rule(org.junit.Rule) MDC(org.slf4j.MDC) HiveTable(com.qlangtech.tis.config.hive.meta.HiveTable) IHiveConnGetter(com.qlangtech.tis.config.hive.IHiveConnGetter) Optional(java.util.Optional) Assert(org.junit.Assert) WriterTemplate(com.qlangtech.tis.plugin.common.WriterTemplate) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) HdfsColMeta(com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta) HdfsColMeta(com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta) OffPartition(com.qlangtech.tis.plugin.datax.hudi.partition.OffPartition) KeyedPluginStore(com.qlangtech.tis.plugin.KeyedPluginStore) DefaultSparkConnGetter(com.qlangtech.tis.config.spark.impl.DefaultSparkConnGetter)

Example 2 with FileSystemFactory

use of com.qlangtech.tis.offline.FileSystemFactory in project plugins by qlangtech.

the class TestDataXHudiWriter method testFlinkSqlTableDDLCreate.

@Test
public void testFlinkSqlTableDDLCreate() throws Exception {
    FileSystemFactory fsFactory = EasyMock.createMock("fsFactory", FileSystemFactory.class);
    ITISFileSystem fs = EasyMock.createMock("fileSystem", ITISFileSystem.class);
    // fs.getRootDir()
    String child = "default/customer_order_relation";
    String dataDir = "hudi";
    IPath rootPath = new HdfsPath(HdfsFileSystemFactoryTestUtils.DEFAULT_HDFS_ADDRESS + "/user/admin");
    IPath tabPath = new HdfsPath(rootPath, child);
    IPath hudiDataPath = new HdfsPath(tabPath, dataDir);
    EasyMock.expect(fs.getPath(rootPath, child)).andReturn(tabPath);
    EasyMock.expect(fs.getPath(tabPath, dataDir)).andReturn(hudiDataPath);
    EasyMock.expect(fs.getRootDir()).andReturn(rootPath);
    EasyMock.expect(fsFactory.getFileSystem()).andReturn(fs);
    HudiTest forTest = createDataXWriter(Optional.of(fsFactory));
    DataxProcessor dataXProcessor = EasyMock.mock("dataXProcessor", DataxProcessor.class);
    File dataXCfg = folder.newFile();
    FileUtils.writeStringToFile(dataXCfg, "{job:{content:[{\"writer\":" + IOUtils.loadResourceFromClasspath(this.getClass(), hudi_datax_writer_assert_without_optional) + "}]}}", TisUTF8.get());
    List<File> dataXFiles = Lists.newArrayList(dataXCfg);
    EasyMock.expect(dataXProcessor.getDataxCfgFileNames(null)).andReturn(dataXFiles);
    DataxProcessor.processorGetter = (dataXName) -> {
        Assert.assertEquals(HdfsFileSystemFactoryTestUtils.testDataXName.getName(), dataXName);
        return dataXProcessor;
    };
    EasyMock.replay(dataXProcessor, fsFactory, fs);
    // IStreamTableCreator.IStreamTableMeta
    // streamTableMeta = forTest.writer.getStreamTableMeta(HudiWriter.targetTableName);
    // Assert.assertNotNull("streamTableMeta can not be null", streamTableMeta);
    // streamTableMeta.getColsMeta();
    // System.out.println(streamTableMeta.createFlinkTableDDL());
    // DataXHudiWriter.HudiStreamTemplateData tplData
    // = (DataXHudiWriter.HudiStreamTemplateData) forTest.writer.decorateMergeData(
    // new TestStreamTemplateData(HdfsFileSystemFactoryTestUtils.testDataXName, HudiWriter.targetTableName));
    // 
    // 
    // StringBuffer createTabDdl = tplData.getSinkFlinkTableDDL(HudiWriter.targetTableName);
    // Assert.assertNotNull(createTabDdl);
    // 
    // System.out.println(createTabDdl);
    EasyMock.verify(dataXProcessor, fsFactory, fs);
}
Also used : DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) HdfsPath(com.qlangtech.tis.hdfs.impl.HdfsPath) IPath(com.qlangtech.tis.fs.IPath) ITISFileSystem(com.qlangtech.tis.fs.ITISFileSystem) File(java.io.File) FileSystemFactory(com.qlangtech.tis.offline.FileSystemFactory) Test(org.junit.Test)

Example 3 with FileSystemFactory

use of com.qlangtech.tis.offline.FileSystemFactory in project plugins by qlangtech.

the class TestHdfsFileSystemFactory method testCreate.

public void testCreate() {
    PluginStore pluginStore = TIS.getPluginStore(FileSystemFactory.class);
    assertNotNull(pluginStore);
    Describable<FileSystemFactory> plugin = pluginStore.getPlugin();
    assertNotNull(plugin);
    FileSystemFactory fsFactory = (FileSystemFactory) plugin;
    ITISFileSystem fileSystem = fsFactory.getFileSystem();
    List<IPathInfo> paths = fileSystem.listChildren(fileSystem.getPath("/"));
    for (IPathInfo i : paths) {
        System.out.println(i.getName());
    }
// plugin.
// 
// assertTrue("real class:" + plugin.getClass().getName(), plugin instanceof HdfsFileSystemFactory);
// HdfsFileSystemFactory fsFactory = (HdfsFileSystemFactory) plugin;
// ITISFileSystem fileSystem = fsFactory.getFileSystem();
// List<IPathInfo> paths = fileSystem.listChildren(fileSystem.getPath(fsFactory.getRootDir() + "/"));
// for (IPathInfo i : paths) {
// System.out.println(i.getName());
// }
}
Also used : PluginStore(com.qlangtech.tis.plugin.PluginStore) IPathInfo(com.qlangtech.tis.fs.IPathInfo) ITISFileSystem(com.qlangtech.tis.fs.ITISFileSystem) FileSystemFactory(com.qlangtech.tis.offline.FileSystemFactory)

Example 4 with FileSystemFactory

use of com.qlangtech.tis.offline.FileSystemFactory in project plugins by qlangtech.

the class BasicHdfsWriterJob method init.

@Override
public void init() {
    getPluginJobConf();
    try {
        if (this.tabDumpParentPath == null) {
            Path path = createPath();
            this.path = String.valueOf(path);
            Objects.requireNonNull(this.tabDumpParentPath, "tabDumpParentPath can not be null");
            FileSystemFactory hdfsFactory = writerPlugin.getFs();
            logger.info("config param {}:{}", Key.PATH, hdfsFactory.getFSAddress());
            cfg.set(Key.DEFAULT_FS, hdfsFactory.getFSAddress());
        }
    } catch (Throwable e) {
        throw new JobPropInitializeException("pmodPath initial error", e);
    }
    Objects.requireNonNull(writerPlugin, "writerPlugin can not be null");
    super.init();
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystemFactory(com.qlangtech.tis.offline.FileSystemFactory)

Example 5 with FileSystemFactory

use of com.qlangtech.tis.offline.FileSystemFactory in project plugins by qlangtech.

the class BasicHdfsWriterJob method createHdfsHelper.

public static HdfsHelper createHdfsHelper(Configuration pluginJobConf, BasicFSWriter hiveWriter) {
    Objects.requireNonNull(pluginJobConf, "pluginJobConf can not be null");
    Objects.requireNonNull(hiveWriter, "hiveWriter can not be null");
    try {
        FileSystemFactory fs = hiveWriter.getFs();
        HdfsHelper hdfsHelper = new HdfsHelper(fs.getFileSystem().unwrap());
        org.apache.hadoop.conf.Configuration cfg = new org.apache.hadoop.conf.Configuration();
        cfg.setClassLoader(TIS.get().getPluginManager().uberClassLoader);
        org.apache.hadoop.mapred.JobConf conf = new JobConf(cfg);
        conf.set(FileSystem.FS_DEFAULT_NAME_KEY, pluginJobConf.getString("defaultFS"));
        conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
        conf.set(JobContext.WORKING_DIR, (fs.getFileSystem().getRootDir().unwrap(Path.class).toString()));
        hdfsHelper.conf = conf;
        return hdfsHelper;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(com.alibaba.datax.common.util.Configuration) FileSystemFactory(com.qlangtech.tis.offline.FileSystemFactory) IOException(java.io.IOException) JobConf(org.apache.hadoop.mapred.JobConf) HdfsHelper(com.alibaba.datax.plugin.writer.hdfswriter.HdfsHelper) JobConf(org.apache.hadoop.mapred.JobConf)

Aggregations

FileSystemFactory (com.qlangtech.tis.offline.FileSystemFactory)6 ITISFileSystem (com.qlangtech.tis.fs.ITISFileSystem)4 IPath (com.qlangtech.tis.fs.IPath)3 Configuration (com.alibaba.datax.common.util.Configuration)2 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)2 DataxProcessor (com.qlangtech.tis.datax.impl.DataxProcessor)2 HdfsPath (com.qlangtech.tis.hdfs.impl.HdfsPath)2 File (java.io.File)2 Path (org.apache.hadoop.fs.Path)2 Test (org.junit.Test)2 HdfsColMeta (com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta)1 HdfsHelper (com.alibaba.datax.plugin.writer.hdfswriter.HdfsHelper)1 HudiWriter (com.alibaba.datax.plugin.writer.hudi.HudiWriter)1 Lists (com.google.common.collect.Lists)1 IHiveConnGetter (com.qlangtech.tis.config.hive.IHiveConnGetter)1 HiveTable (com.qlangtech.tis.config.hive.meta.HiveTable)1 IHiveMetaStore (com.qlangtech.tis.config.hive.meta.IHiveMetaStore)1 ISparkConnGetter (com.qlangtech.tis.config.spark.ISparkConnGetter)1 DefaultSparkConnGetter (com.qlangtech.tis.config.spark.impl.DefaultSparkConnGetter)1 TargetResName (com.qlangtech.tis.coredefine.module.action.TargetResName)1