Search in sources :

Example 1 with Memoizer

use of com.qlangtech.tis.util.Memoizer in project plugins by qlangtech.

the class DataXHbase11xsqlReader method getSubTasks.

@Override
public Iterator<IDataxReaderContext> getSubTasks() {
    MySQLDataSourceFactory dsFactory = (MySQLDataSourceFactory) this.getDataSourceFactory();
    Memoizer<String, List<ColumnMetaData>> tabColsMap = new Memoizer<String, List<ColumnMetaData>>() {

        @Override
        public List<ColumnMetaData> compute(String tab) {
            return dsFactory.getTableMetadata(tab);
        }
    };
    AtomicInteger selectedTabIndex = new AtomicInteger(0);
    AtomicInteger taskIndex = new AtomicInteger(0);
    final int selectedTabsSize = this.selectedTabs.size();
    AtomicReference<Iterator<IDataSourceDumper>> dumperItRef = new AtomicReference<>();
    return new Iterator<IDataxReaderContext>() {

        @Override
        public boolean hasNext() {
            Iterator<IDataSourceDumper> dumperIt = initDataSourceDumperIterator();
            if (dumperIt.hasNext()) {
                return true;
            } else {
                if (selectedTabIndex.get() >= selectedTabsSize) {
                    return false;
                } else {
                    dumperItRef.set(null);
                    initDataSourceDumperIterator();
                    return true;
                }
            }
        }

        private Iterator<IDataSourceDumper> initDataSourceDumperIterator() {
            Iterator<IDataSourceDumper> dumperIt;
            if ((dumperIt = dumperItRef.get()) == null) {
                SelectedTab tab = selectedTabs.get(selectedTabIndex.getAndIncrement());
                if (StringUtils.isEmpty(tab.getName())) {
                    throw new IllegalStateException("tableName can not be null");
                }
                // List<ColumnMetaData> tableMetadata = null;
                // IDataSourceDumper dumper = null;
                DataDumpers dataDumpers = null;
                TISTable tisTab = new TISTable();
                tisTab.setTableName(tab.getName());
                dataDumpers = dsFactory.getDataDumpers(tisTab);
                dumperIt = dataDumpers.dumpers;
                dumperItRef.set(dumperIt);
            }
            return dumperIt;
        }

        @Override
        public IDataxReaderContext next() {
            Iterator<IDataSourceDumper> dumperIterator = dumperItRef.get();
            Objects.requireNonNull(dumperIterator, "dumperIterator can not be null,selectedTabIndex:" + selectedTabIndex.get());
            IDataSourceDumper dumper = dumperIterator.next();
            SelectedTab tab = selectedTabs.get(selectedTabIndex.get() - 1);
            MySQLDataXReaderContext dataxContext = new MySQLDataXReaderContext(tab.getName() + "_" + taskIndex.getAndIncrement(), tab.getName());
            dataxContext.jdbcUrl = dumper.getDbHost();
            dataxContext.tabName = tab.getName();
            dataxContext.username = dsFactory.getUserName();
            dataxContext.password = dsFactory.getPassword();
            dataxContext.setWhere(tab.getWhere());
            List<ColumnMetaData> tableMetadata = tabColsMap.get(tab.getName());
            if (tab.isAllCols()) {
                dataxContext.cols = tableMetadata.stream().map((t) -> t.getValue()).collect(Collectors.toList());
            } else {
                dataxContext.cols = tableMetadata.stream().filter((col) -> {
                    return tab.containCol(col.getKey());
                }).map((t) -> t.getValue()).collect(Collectors.toList());
            }
            return dataxContext;
        }
    };
}
Also used : Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) StringUtils(org.apache.commons.lang.StringUtils) Iterator(java.util.Iterator) TIS(com.qlangtech.tis.TIS) Descriptor(com.qlangtech.tis.extension.Descriptor) FormField(com.qlangtech.tis.plugin.annotation.FormField) SubForm(com.qlangtech.tis.plugin.annotation.SubForm) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataxUtils(com.qlangtech.tis.offline.DataxUtils) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) List(java.util.List) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Example 2 with Memoizer

use of com.qlangtech.tis.util.Memoizer in project plugins by qlangtech.

the class DataXHbase11xReader method getSubTasks.

@Override
public Iterator<IDataxReaderContext> getSubTasks() {
    MySQLDataSourceFactory dsFactory = (MySQLDataSourceFactory) this.getDataSourceFactory();
    Memoizer<String, List<ColumnMetaData>> tabColsMap = new Memoizer<String, List<ColumnMetaData>>() {

        @Override
        public List<ColumnMetaData> compute(String tab) {
            return dsFactory.getTableMetadata(tab);
        }
    };
    AtomicInteger selectedTabIndex = new AtomicInteger(0);
    AtomicInteger taskIndex = new AtomicInteger(0);
    final int selectedTabsSize = this.selectedTabs.size();
    AtomicReference<Iterator<IDataSourceDumper>> dumperItRef = new AtomicReference<>();
    return new Iterator<IDataxReaderContext>() {

        @Override
        public boolean hasNext() {
            Iterator<IDataSourceDumper> dumperIt = initDataSourceDumperIterator();
            if (dumperIt.hasNext()) {
                return true;
            } else {
                if (selectedTabIndex.get() >= selectedTabsSize) {
                    return false;
                } else {
                    dumperItRef.set(null);
                    initDataSourceDumperIterator();
                    return true;
                }
            }
        }

        private Iterator<IDataSourceDumper> initDataSourceDumperIterator() {
            Iterator<IDataSourceDumper> dumperIt;
            if ((dumperIt = dumperItRef.get()) == null) {
                SelectedTab tab = selectedTabs.get(selectedTabIndex.getAndIncrement());
                if (StringUtils.isEmpty(tab.getName())) {
                    throw new IllegalStateException("tableName can not be null");
                }
                // List<ColumnMetaData> tableMetadata = null;
                // IDataSourceDumper dumper = null;
                DataDumpers dataDumpers = null;
                TISTable tisTab = new TISTable();
                tisTab.setTableName(tab.getName());
                dataDumpers = dsFactory.getDataDumpers(tisTab);
                dumperIt = dataDumpers.dumpers;
                dumperItRef.set(dumperIt);
            }
            return dumperIt;
        }

        @Override
        public IDataxReaderContext next() {
            Iterator<IDataSourceDumper> dumperIterator = dumperItRef.get();
            Objects.requireNonNull(dumperIterator, "dumperIterator can not be null,selectedTabIndex:" + selectedTabIndex.get());
            IDataSourceDumper dumper = dumperIterator.next();
            SelectedTab tab = selectedTabs.get(selectedTabIndex.get() - 1);
            MySQLDataXReaderContext dataxContext = new MySQLDataXReaderContext(tab.getName() + "_" + taskIndex.getAndIncrement(), tab.getName());
            dataxContext.jdbcUrl = dumper.getDbHost();
            dataxContext.tabName = tab.getName();
            dataxContext.username = dsFactory.getUserName();
            dataxContext.password = dsFactory.getPassword();
            dataxContext.setWhere(tab.getWhere());
            List<ColumnMetaData> tableMetadata = tabColsMap.get(tab.getName());
            if (tab.isAllCols()) {
                dataxContext.cols = tableMetadata.stream().map((t) -> t.getValue()).collect(Collectors.toList());
            } else {
                dataxContext.cols = tableMetadata.stream().filter((col) -> {
                    return tab.containCol(col.getKey());
                }).map((t) -> t.getValue()).collect(Collectors.toList());
            }
            return dataxContext;
        }
    };
}
Also used : Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) StringUtils(org.apache.commons.lang.StringUtils) Iterator(java.util.Iterator) TIS(com.qlangtech.tis.TIS) Descriptor(com.qlangtech.tis.extension.Descriptor) FormField(com.qlangtech.tis.plugin.annotation.FormField) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) List(java.util.List) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Example 3 with Memoizer

use of com.qlangtech.tis.util.Memoizer in project plugins by qlangtech.

the class DataXOdpsReader method getSubTasks.

@Override
public Iterator<IDataxReaderContext> getSubTasks() {
    MySQLDataSourceFactory dsFactory = (MySQLDataSourceFactory) this.getDataSourceFactory();
    Memoizer<String, List<ColumnMetaData>> tabColsMap = new Memoizer<String, List<ColumnMetaData>>() {

        @Override
        public List<ColumnMetaData> compute(String tab) {
            return dsFactory.getTableMetadata(tab);
        }
    };
    AtomicInteger selectedTabIndex = new AtomicInteger(0);
    AtomicInteger taskIndex = new AtomicInteger(0);
    final int selectedTabsSize = this.selectedTabs.size();
    AtomicReference<Iterator<IDataSourceDumper>> dumperItRef = new AtomicReference<>();
    return new Iterator<IDataxReaderContext>() {

        @Override
        public boolean hasNext() {
            Iterator<IDataSourceDumper> dumperIt = initDataSourceDumperIterator();
            if (dumperIt.hasNext()) {
                return true;
            } else {
                if (selectedTabIndex.get() >= selectedTabsSize) {
                    return false;
                } else {
                    dumperItRef.set(null);
                    initDataSourceDumperIterator();
                    return true;
                }
            }
        }

        private Iterator<IDataSourceDumper> initDataSourceDumperIterator() {
            Iterator<IDataSourceDumper> dumperIt;
            if ((dumperIt = dumperItRef.get()) == null) {
                SelectedTab tab = selectedTabs.get(selectedTabIndex.getAndIncrement());
                if (StringUtils.isEmpty(tab.getName())) {
                    throw new IllegalStateException("tableName can not be null");
                }
                // List<ColumnMetaData> tableMetadata = null;
                // IDataSourceDumper dumper = null;
                DataDumpers dataDumpers = null;
                TISTable tisTab = new TISTable();
                tisTab.setTableName(tab.getName());
                dataDumpers = dsFactory.getDataDumpers(tisTab);
                dumperIt = dataDumpers.dumpers;
                dumperItRef.set(dumperIt);
            }
            return dumperIt;
        }

        @Override
        public IDataxReaderContext next() {
            Iterator<IDataSourceDumper> dumperIterator = dumperItRef.get();
            Objects.requireNonNull(dumperIterator, "dumperIterator can not be null,selectedTabIndex:" + selectedTabIndex.get());
            IDataSourceDumper dumper = dumperIterator.next();
            SelectedTab tab = selectedTabs.get(selectedTabIndex.get() - 1);
            MySQLDataXReaderContext dataxContext = new MySQLDataXReaderContext(tab.getName() + "_" + taskIndex.getAndIncrement(), tab.getName());
            dataxContext.jdbcUrl = dumper.getDbHost();
            dataxContext.tabName = tab.getName();
            dataxContext.username = dsFactory.getUserName();
            dataxContext.password = dsFactory.getPassword();
            dataxContext.setWhere(tab.getWhere());
            List<ColumnMetaData> tableMetadata = tabColsMap.get(tab.getName());
            if (tab.isAllCols()) {
                dataxContext.cols = tableMetadata.stream().map((t) -> t.getValue()).collect(Collectors.toList());
            } else {
                dataxContext.cols = tableMetadata.stream().filter((col) -> {
                    return tab.containCol(col.getKey());
                }).map((t) -> t.getValue()).collect(Collectors.toList());
            }
            return dataxContext;
        }
    };
}
Also used : Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) StringUtils(org.apache.commons.lang.StringUtils) Iterator(java.util.Iterator) TIS(com.qlangtech.tis.TIS) Descriptor(com.qlangtech.tis.extension.Descriptor) FormField(com.qlangtech.tis.plugin.annotation.FormField) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) List(java.util.List) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Example 4 with Memoizer

use of com.qlangtech.tis.util.Memoizer in project plugins by qlangtech.

the class DataXHbase20xsqlReader method getSubTasks.

@Override
public Iterator<IDataxReaderContext> getSubTasks() {
    MySQLDataSourceFactory dsFactory = (MySQLDataSourceFactory) this.getDataSourceFactory();
    Memoizer<String, List<ColumnMetaData>> tabColsMap = new Memoizer<String, List<ColumnMetaData>>() {

        @Override
        public List<ColumnMetaData> compute(String tab) {
            return dsFactory.getTableMetadata(tab);
        }
    };
    AtomicInteger selectedTabIndex = new AtomicInteger(0);
    AtomicInteger taskIndex = new AtomicInteger(0);
    final int selectedTabsSize = this.selectedTabs.size();
    AtomicReference<Iterator<IDataSourceDumper>> dumperItRef = new AtomicReference<>();
    return new Iterator<IDataxReaderContext>() {

        @Override
        public boolean hasNext() {
            Iterator<IDataSourceDumper> dumperIt = initDataSourceDumperIterator();
            if (dumperIt.hasNext()) {
                return true;
            } else {
                if (selectedTabIndex.get() >= selectedTabsSize) {
                    return false;
                } else {
                    dumperItRef.set(null);
                    initDataSourceDumperIterator();
                    return true;
                }
            }
        }

        private Iterator<IDataSourceDumper> initDataSourceDumperIterator() {
            Iterator<IDataSourceDumper> dumperIt;
            if ((dumperIt = dumperItRef.get()) == null) {
                SelectedTab tab = selectedTabs.get(selectedTabIndex.getAndIncrement());
                if (StringUtils.isEmpty(tab.getName())) {
                    throw new IllegalStateException("tableName can not be null");
                }
                // List<ColumnMetaData> tableMetadata = null;
                // IDataSourceDumper dumper = null;
                DataDumpers dataDumpers = null;
                TISTable tisTab = new TISTable();
                tisTab.setTableName(tab.getName());
                dataDumpers = dsFactory.getDataDumpers(tisTab);
                dumperIt = dataDumpers.dumpers;
                dumperItRef.set(dumperIt);
            }
            return dumperIt;
        }

        @Override
        public IDataxReaderContext next() {
            Iterator<IDataSourceDumper> dumperIterator = dumperItRef.get();
            Objects.requireNonNull(dumperIterator, "dumperIterator can not be null,selectedTabIndex:" + selectedTabIndex.get());
            IDataSourceDumper dumper = dumperIterator.next();
            SelectedTab tab = selectedTabs.get(selectedTabIndex.get() - 1);
            MySQLDataXReaderContext dataxContext = new MySQLDataXReaderContext(tab.getName() + "_" + taskIndex.getAndIncrement(), tab.getName());
            dataxContext.jdbcUrl = dumper.getDbHost();
            dataxContext.tabName = tab.getName();
            dataxContext.username = dsFactory.getUserName();
            dataxContext.password = dsFactory.getPassword();
            dataxContext.setWhere(tab.getWhere());
            List<ColumnMetaData> tableMetadata = tabColsMap.get(tab.getName());
            if (tab.isAllCols()) {
                dataxContext.cols = tableMetadata.stream().map((t) -> t.getValue()).collect(Collectors.toList());
            } else {
                dataxContext.cols = tableMetadata.stream().filter((col) -> {
                    return tab.containCol(col.getKey());
                }).map((t) -> t.getValue()).collect(Collectors.toList());
            }
            return dataxContext;
        }
    };
}
Also used : Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) StringUtils(org.apache.commons.lang.StringUtils) Iterator(java.util.Iterator) TIS(com.qlangtech.tis.TIS) Descriptor(com.qlangtech.tis.extension.Descriptor) FormField(com.qlangtech.tis.plugin.annotation.FormField) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory) Memoizer(com.qlangtech.tis.util.Memoizer) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) List(java.util.List) MySQLDataSourceFactory(com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)

Aggregations

TIS (com.qlangtech.tis.TIS)4 IDataxReaderContext (com.qlangtech.tis.datax.IDataxReaderContext)4 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)4 Descriptor (com.qlangtech.tis.extension.Descriptor)4 TISExtension (com.qlangtech.tis.extension.TISExtension)4 IOUtils (com.qlangtech.tis.extension.impl.IOUtils)4 FormField (com.qlangtech.tis.plugin.annotation.FormField)4 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)4 Validator (com.qlangtech.tis.plugin.annotation.Validator)4 MySQLDataSourceFactory (com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory)4 Memoizer (com.qlangtech.tis.util.Memoizer)4 Iterator (java.util.Iterator)4 List (java.util.List)4 Objects (java.util.Objects)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Collectors (java.util.stream.Collectors)4 StringUtils (org.apache.commons.lang.StringUtils)4 Context (com.alibaba.citrus.turbine.Context)1 DataxUtils (com.qlangtech.tis.offline.DataxUtils)1