| 57 | private static final String CHECK_TYPE_BLOOM_FILTER = "bloom-filter"; |
| 58 | |
| 59 | public static void main(Configuration conf, String[] args) throws Exception { |
| 60 | Options opts = createOptions(); |
| 61 | CommandLine cli = new DefaultParser().parse(opts, args); |
| 62 | HelpFormatter formatter = new HelpFormatter(); |
| 63 | if (cli.hasOption('h')) { |
| 64 | formatter.printHelp("check", opts); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | String type = cli.getOptionValue("type"); |
| 69 | if (type == null || |
| 70 | (!type.equals(CHECK_TYPE_PREDICATE) && |
| 71 | !type.equals(CHECK_TYPE_STAT) && |
| 72 | !type.equals(CHECK_TYPE_BLOOM_FILTER))) { |
| 73 | System.err.printf("type %s not support %n", type); |
| 74 | formatter.printHelp("check", opts); |
| 75 | return; |
| 76 | } |
| 77 | String column = cli.getOptionValue("column"); |
| 78 | if (column == null || column.isEmpty()) { |
| 79 | System.err.println("column is null"); |
| 80 | formatter.printHelp("check", opts); |
| 81 | return; |
| 82 | } |
| 83 | String[] values = cli.getOptionValues("values"); |
| 84 | if (values == null || values.length == 0) { |
| 85 | System.err.println("values is null"); |
| 86 | formatter.printHelp("check", opts); |
| 87 | return; |
| 88 | } |
| 89 | boolean ignoreExtension = cli.hasOption("ignoreExtension"); |
| 90 | |
| 91 | List<Path> inputFiles = new ArrayList<>(); |
| 92 | String[] files = cli.getArgs(); |
| 93 | for (String root : files) { |
| 94 | Path rootPath = new Path(root); |
| 95 | FileSystem fs = rootPath.getFileSystem(conf); |
| 96 | for (RemoteIterator<LocatedFileStatus> itr = fs.listFiles(rootPath, true); itr.hasNext(); ) { |
| 97 | LocatedFileStatus status = itr.next(); |
| 98 | if (status.isFile() && (ignoreExtension || status.getPath().getName().endsWith(".orc"))) { |
| 99 | inputFiles.add(status.getPath()); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | if (inputFiles.isEmpty()) { |
| 104 | System.err.println("No files found."); |
| 105 | System.exit(1); |
| 106 | } |
| 107 | |
| 108 | for (Path inputFile : inputFiles) { |
| 109 | System.out.println("input file: " + inputFile); |
| 110 | FileSystem fs = inputFile.getFileSystem(conf); |
| 111 | try (Reader reader = OrcFile.createReader(inputFile, |
| 112 | OrcFile.readerOptions(conf).filesystem(fs))) { |
| 113 | RecordReaderImpl rows = (RecordReaderImpl) reader.rows(); |
| 114 | TypeDescription schema = reader.getSchema(); |
| 115 | boolean[] includedColumns = OrcUtils.includeColumns(column, schema); |
| 116 | int colIndex = -1; |