org.apache.parquet.io.RecordReader Java Examples
The following examples show how to use
org.apache.parquet.io.RecordReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParquetResolverTest.java From pxf with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private List<Group> readParquetFile(String file, long expectedSize, MessageType schema) throws IOException { List<Group> result = new ArrayList<>(); String parquetFile = Objects.requireNonNull(getClass().getClassLoader().getResource("parquet/" + file)).getPath(); Path path = new Path(parquetFile); ParquetFileReader fileReader = new ParquetFileReader(new Configuration(), path, ParquetMetadataConverter.NO_FILTER); PageReadStore rowGroup; while ((rowGroup = fileReader.readNextRowGroup()) != null) { MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema); RecordReader<Group> recordReader = columnIO.getRecordReader(rowGroup, new GroupRecordConverter(schema)); long rowCount = rowGroup.getRowCount(); for (long i = 0; i < rowCount; i++) { result.add(recordReader.read()); } } fileReader.close(); assertEquals(expectedSize, result.size()); return result; }
Example #2
Source File: TupleConsumerPerfTest.java From parquet-mr with Apache License 2.0 | 6 votes |
private static void read(PageReadStore columns, String pigSchemaString, String message) throws ParserException { System.out.println(message); MessageColumnIO columnIO = newColumnFactory(pigSchemaString); TupleReadSupport tupleReadSupport = new TupleReadSupport(); Map<String, String> pigMetaData = pigMetaData(pigSchemaString); MessageType schema = new PigSchemaConverter().convert(Utils.getSchemaFromString(pigSchemaString)); ReadContext init = tupleReadSupport.init(null, pigMetaData, schema); RecordMaterializer<Tuple> recordConsumer = tupleReadSupport.prepareForRead(null, pigMetaData, schema, init); RecordReader<Tuple> recordReader = columnIO.getRecordReader(columns, recordConsumer); // TODO: put this back // if (DEBUG) { // recordConsumer = new RecordConsumerLoggingWrapper(recordConsumer); // } read(recordReader, 10000, pigSchemaString); read(recordReader, 10000, pigSchemaString); read(recordReader, 10000, pigSchemaString); read(recordReader, 10000, pigSchemaString); read(recordReader, 10000, pigSchemaString); read(recordReader, 100000, pigSchemaString); read(recordReader, 1000000, pigSchemaString); System.out.println(); }
Example #3
Source File: ParquetRecordReader.java From flink with Apache License 2.0 | 5 votes |
private RecordReader<T> createRecordReader(PageReadStore pages) throws IOException { if (pages == null) { throw new IOException( "Expecting more rows but reached last block. Read " + numReadRecords + " out of " + numTotalRecords); } MessageColumnIO columnIO = columnIOFactory.getColumnIO(readSchema, fileSchema, true); return columnIO.getRecordReader(pages, recordMaterializer, filter); }
Example #4
Source File: SparkModelParser.java From ignite with Apache License 2.0 | 5 votes |
/** * Load Decision Tree model. * * @param pathToMdl Path to model. * @param learningEnvironment Learning environment. */ private static Model loadDecisionTreeModel(String pathToMdl, LearningEnvironment learningEnvironment) { try (ParquetFileReader r = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(pathToMdl), new Configuration()))) { PageReadStore pages; final MessageType schema = r.getFooter().getFileMetaData().getSchema(); final MessageColumnIO colIO = new ColumnIOFactory().getColumnIO(schema); final Map<Integer, NodeData> nodes = new TreeMap<>(); while (null != (pages = r.readNextRowGroup())) { final long rows = pages.getRowCount(); final RecordReader recordReader = colIO.getRecordReader(pages, new GroupRecordConverter(schema)); for (int i = 0; i < rows; i++) { final SimpleGroup g = (SimpleGroup)recordReader.read(); NodeData nodeData = extractNodeDataFromParquetRow(g); nodes.put(nodeData.id, nodeData); } } return buildDecisionTreeModel(nodes); } catch (IOException e) { String msg = "Error reading parquet file: " + e.getMessage(); learningEnvironment.logger().log(MLLogger.VerboseLevel.HIGH, msg); e.printStackTrace(); } return null; }
Example #5
Source File: SparkModelParser.java From ignite with Apache License 2.0 | 5 votes |
/** * Load SVM model. * * @param pathToMdl Path to model. * @param learningEnvironment Learning environment. */ private static Model loadLinearSVMModel(String pathToMdl, LearningEnvironment learningEnvironment) { Vector coefficients = null; double interceptor = 0; try (ParquetFileReader r = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(pathToMdl), new Configuration()))) { PageReadStore pages; final MessageType schema = r.getFooter().getFileMetaData().getSchema(); final MessageColumnIO colIO = new ColumnIOFactory().getColumnIO(schema); while (null != (pages = r.readNextRowGroup())) { final long rows = pages.getRowCount(); final RecordReader recordReader = colIO.getRecordReader(pages, new GroupRecordConverter(schema)); for (int i = 0; i < rows; i++) { final SimpleGroup g = (SimpleGroup)recordReader.read(); interceptor = readSVMInterceptor(g); coefficients = readSVMCoefficients(g); } } } catch (IOException e) { String msg = "Error reading parquet file: " + e.getMessage(); learningEnvironment.logger().log(MLLogger.VerboseLevel.HIGH, msg); e.printStackTrace(); } return new SVMLinearClassificationModel(coefficients, interceptor); }
Example #6
Source File: SparkModelParser.java From ignite with Apache License 2.0 | 5 votes |
/** * Load linear regression model. * * @param pathToMdl Path to model. * @param learningEnvironment Learning environment. */ private static Model loadLinRegModel(String pathToMdl, LearningEnvironment learningEnvironment) { Vector coefficients = null; double interceptor = 0; try (ParquetFileReader r = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(pathToMdl), new Configuration()))) { PageReadStore pages; final MessageType schema = r.getFooter().getFileMetaData().getSchema(); final MessageColumnIO colIO = new ColumnIOFactory().getColumnIO(schema); while (null != (pages = r.readNextRowGroup())) { final long rows = pages.getRowCount(); final RecordReader recordReader = colIO.getRecordReader(pages, new GroupRecordConverter(schema)); for (int i = 0; i < rows; i++) { final SimpleGroup g = (SimpleGroup)recordReader.read(); interceptor = readLinRegInterceptor(g); coefficients = readLinRegCoefficients(g); } } } catch (IOException e) { String msg = "Error reading parquet file: " + e.getMessage(); learningEnvironment.logger().log(MLLogger.VerboseLevel.HIGH, msg); e.printStackTrace(); } return new LinearRegressionModel(coefficients, interceptor); }
Example #7
Source File: SparkModelParser.java From ignite with Apache License 2.0 | 5 votes |
/** * Load logistic regression model. * * @param pathToMdl Path to model. * @param learningEnvironment Learning environment. */ private static Model loadLogRegModel(String pathToMdl, LearningEnvironment learningEnvironment) { Vector coefficients = null; double interceptor = 0; try (ParquetFileReader r = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(pathToMdl), new Configuration()))) { PageReadStore pages; final MessageType schema = r.getFooter().getFileMetaData().getSchema(); final MessageColumnIO colIO = new ColumnIOFactory().getColumnIO(schema); while (null != (pages = r.readNextRowGroup())) { final long rows = pages.getRowCount(); final RecordReader recordReader = colIO.getRecordReader(pages, new GroupRecordConverter(schema)); for (int i = 0; i < rows; i++) { final SimpleGroup g = (SimpleGroup)recordReader.read(); interceptor = readInterceptor(g); coefficients = readCoefficients(g); } } } catch (IOException e) { String msg = "Error reading parquet file: " + e.getMessage(); learningEnvironment.logger().log(MLLogger.VerboseLevel.HIGH, msg); e.printStackTrace(); } return new LogisticRegressionModel(coefficients, interceptor); }
Example #8
Source File: ParquetRecordReader.java From flink with Apache License 2.0 | 5 votes |
private RecordReader<T> createRecordReader(PageReadStore pages) throws IOException { if (pages == null) { throw new IOException( "Expecting more rows but reached last block. Read " + numReadRecords + " out of " + numTotalRecords); } MessageColumnIO columnIO = columnIOFactory.getColumnIO(readSchema, fileSchema, true); return columnIO.getRecordReader(pages, recordMaterializer, filter); }
Example #9
Source File: TestParquetReadProtocol.java From parquet-mr with Apache License 2.0 | 5 votes |
private <T extends TBase<?,?>> void validate(T expected) throws TException { @SuppressWarnings("unchecked") final Class<T> thriftClass = (Class<T>)expected.getClass(); final MemPageStore memPageStore = new MemPageStore(1); final ThriftSchemaConverter schemaConverter = new ThriftSchemaConverter(); final MessageType schema = schemaConverter.convert(thriftClass); LOG.info("{}", schema); final MessageColumnIO columnIO = new ColumnIOFactory(true).getColumnIO(schema); final ColumnWriteStoreV1 columns = new ColumnWriteStoreV1(memPageStore, ParquetProperties.builder() .withPageSize(10000) .withDictionaryEncoding(false) .build()); final RecordConsumer recordWriter = columnIO.getRecordWriter(columns); final StructType thriftType = schemaConverter.toStructType(thriftClass); ParquetWriteProtocol parquetWriteProtocol = new ParquetWriteProtocol(recordWriter, columnIO, thriftType); expected.write(parquetWriteProtocol); recordWriter.flush(); columns.flush(); ThriftRecordConverter<T> converter = new TBaseRecordConverter<T>(thriftClass, schema, thriftType); final RecordReader<T> recordReader = columnIO.getRecordReader(memPageStore, converter); final T result = recordReader.read(); assertEquals(expected, result); }
Example #10
Source File: TupleConsumerPerfTest.java From parquet-mr with Apache License 2.0 | 5 votes |
private static void read(RecordReader<Tuple> recordReader, int count, String pigSchemaString) throws ParserException { long t0 = System.currentTimeMillis(); Tuple tuple = null; for (int i = 0; i < count; i++) { tuple = recordReader.read(); } if (tuple == null) { throw new RuntimeException(); } long t1 = System.currentTimeMillis(); long t = t1-t0; float err = (float)100 * 2 / t; // (+/- 1 ms) System.out.printf("read %,9d recs in %,5d ms at %,9d rec/s err: %3.2f%%\n", count , t, t == 0 ? 0 : count * 1000 / t, err); }
Example #11
Source File: SparkModelParser.java From ignite with Apache License 2.0 | 4 votes |
/** * Load K-Means model. * * @param pathToMdl Path to model. * @param learningEnvironment learningEnvironment */ private static Model loadKMeansModel(String pathToMdl, LearningEnvironment learningEnvironment) { Vector[] centers = null; try (ParquetFileReader r = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(pathToMdl), new Configuration()))) { PageReadStore pages; final MessageType schema = r.getFooter().getFileMetaData().getSchema(); final MessageColumnIO colIO = new ColumnIOFactory().getColumnIO(schema); while (null != (pages = r.readNextRowGroup())) { final int rows = (int)pages.getRowCount(); final RecordReader recordReader = colIO.getRecordReader(pages, new GroupRecordConverter(schema)); centers = new DenseVector[rows]; for (int i = 0; i < rows; i++) { final SimpleGroup g = (SimpleGroup)recordReader.read(); // final int clusterIdx = g.getInteger(0, 0); Group clusterCenterCoeff = g.getGroup(1, 0).getGroup(3, 0); final int amountOfCoefficients = clusterCenterCoeff.getFieldRepetitionCount(0); centers[i] = new DenseVector(amountOfCoefficients); for (int j = 0; j < amountOfCoefficients; j++) { double coefficient = clusterCenterCoeff.getGroup(0, j).getDouble(0, 0); centers[i].set(j, coefficient); } } } } catch (IOException e) { String msg = "Error reading parquet file: " + e.getMessage(); learningEnvironment.logger().log(MLLogger.VerboseLevel.HIGH, msg); e.printStackTrace(); } return new KMeansModel(centers, new EuclideanDistance()); }