class FilterSpliter {

    public static Map<FilterType, IFilter> splitByIndex(List<IFilter> DNFNode, TableNode table) {
        Map<FilterType, IFilter> filters = new HashMap();
        Map<Object, List<IFilter>> columnAndItsFilters = FilterUtils.toColumnFiltersMap(DNFNode);
        IndexMeta index = table.getIndexUsed();
        if (index == null) { // 默认选择主键
            index = table.getTableMeta().getPrimaryIndex();
        }

        List<ISelectable> indexKeyColumns = new ArrayList(0);
        List<ISelectable> indexValueColumns = new ArrayList(0);
        if (index != null) {
            indexKeyColumns = OptimizerUtils.columnMetaListToIColumnList(index.getKeyColumns(), table.getTableName());
            indexValueColumns = OptimizerUtils.columnMetaListToIColumnList(index.getValueColumns(),
                table.getTableName());
        }

        List<IFilter> indexQueryKeyFilters = new LinkedList();
        List<IFilter> indexQueryValueFilters = new LinkedList();
        List<IFilter> resultFilters = new LinkedList(DNFNode);
        for (int i = 0; i < indexKeyColumns.size(); i++) {
            // 不等于,is null, is not null, like 应该按照valueFilter处理
            List<IFilter> fs = columnAndItsFilters.get(indexKeyColumns.get(i));
            if (fs != null) {
                for (IFilter f : fs) {
                    // filter右边不是常量的，不能走索引
                    if (((IBooleanFilter) f).getValue() != null
                        && (((IBooleanFilter) f).getValue() instanceof ISelectable)) {
                        continue;
                    }

                    if (f != null && f.getOperation() != OPERATION.NOT_EQ && f.getOperation() != OPERATION.IS_NOT_NULL
                        && f.getOperation() != OPERATION.IS_NULL && f.getOperation() != OPERATION.LIKE) {
                        indexQueryKeyFilters.add(f);
                    } else {
                        indexQueryValueFilters.add(f);
                    }
                }
                fs.clear();
            }
        }

        for (int i = 0; i < indexValueColumns.size(); i++) {
            // 不等于,is null, is not null, like 应该按照valueFilter处理
            List<IFilter> fs = columnAndItsFilters.get(indexValueColumns.get(i));
            if (fs != null) {
                for (IFilter f : fs) {
                    // filter右边不是常量的，不能走索引
                    if (((IBooleanFilter) f).getValue() != null
                        && (((IBooleanFilter) f).getValue() instanceof ISelectable)) {
                        continue;
                    }

                    indexQueryValueFilters.add(f);
                }
                fs.clear();
            }

        }
        resultFilters.removeAll(indexQueryKeyFilters);
        resultFilters.removeAll(indexQueryValueFilters);

        IFilter indexQueryKeyTree = FilterUtils.DNFToAndLogicTree(indexQueryKeyFilters);
        IFilter indexQueryValueTree = FilterUtils.DNFToAndLogicTree(indexQueryValueFilters);
        IFilter resultTree = FilterUtils.DNFToAndLogicTree(resultFilters);
        filters.put(FilterType.IndexQueryKeyFilter, indexQueryKeyTree);
        filters.put(FilterType.IndexQueryValueFilter, indexQueryValueTree);
        filters.put(FilterType.ResultFilter, resultTree);
        return filters;
    }

}