incorporate fields later for projectable table scans
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/sources/fs/JavaCSVTableSource.java, đặc biệt là member fields đang được comment và các entry point evaluate/createStream/parseLine. Theo dõi cách các phép quét bảng có thể project được biểu diễn ở những nơi khác trong tích hợp SQL, sau đó đưa các field đã chọn vào để các phép quét đã project tạo ra các record như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
incorporate fields later for projectable table scans
private final ImmutableIntList fields;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wayang.api.sql.sources.fs;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.commons.io.IOUtils;
import org.apache.wayang.basic.channels.FileChannel;
import org.apache.wayang.basic.data.Record;
import org.apache.wayang.core.api.exception.WayangException;
import org.apache.wayang.core.optimizer.OptimizationContext;
import org.apache.wayang.core.plan.wayangplan.ExecutionOperator;
import org.apache.wayang.core.plan.wayangplan.UnarySource;
import org.apache.wayang.core.platform.ChannelDescriptor;
import org.apache.wayang.core.platform.ChannelInstance;
import org.apache.wayang.core.platform.lineage.ExecutionLineageNode;
import org.apache.wayang.core.types.DataSetType;
import org.apache.wayang.core.util.Tuple;
import org.apache.wayang.core.util.fs.FileSystem;
import org.apache.wayang.core.util.fs.FileSystems;
import org.apache.wayang.core.util.fs.FileUtils;
import org.apache.wayang.java.channels.StreamChannel;
import org.apache.wayang.java.execution.JavaExecutor;
import org.apache.wayang.java.operators.JavaExecutionOperator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class JavaCSVTableSource<T> extends UnarySource<T> implements JavaExecutionOperator {
private final String sourcePath;
private final List<RelDataType> fieldTypes;
// TODO: incorporate fields later for projectable table scans
// private final ImmutableIntList fields;
public JavaCSVTableSource(String sourcePath, DataSetType type, List<RelDataType> fieldTypes) {
super(type);
this.sourcePath = sourcePath;
this.fieldTypes = fieldTypes;
}
/*public JavaCSVTableSource(DataSetType<T> type) {
this(null, type);
}*/
@Override
public Tuple<Collection<ExecutionLineageNode>, Collection<ChannelInstance>> evaluate(
ChannelInstance[] inputs,
ChannelInstance[] outputs,
JavaExecutor javaExecutor,
OptimizationContext.OperatorContext operatorContext) {
assert outputs.length == this.getNumOutputs();
final String path;
if (this.sourcePath == null) {
final FileChannel.Instance input = (FileChannel.Instance) inputs[0];
path = input.getSinglePath();
} else {
assert inputs.length == 0;
path = this.sourcePath;
}
final String actualInputPath = FileSystems.findActualSingleInputPath(path);
Stream<T> stream = this.createStream(actualInputPath);
((StreamChannel.Instance) outputs[0]).accept(stream);
return ExecutionOperator.modelLazyExecution(inputs, outputs, operatorContext);
}
private Stream<T> createStream(String actualInputPath) {
Function<String, T> parser = this::parseLine;
return streamLines(actualInputPath).map(parser);
}
private T parseLine(String s) {
Class typeClass = this.getType().getDataUnitType().getTypeClass();
assert typeClass == Record.class;
try {
String[] tokens = CsvRowConverter.parseLine(s);
if (tokens.length != fieldTypes.size()) {
throw new IllegalStateException(String.format("Error while parsing CSV file %s at line %s", sourcePath, s));
}
final Object[] objects = new Object[tokens.length];
for (int i = 0; i < tokens.length; i++) {
objects[i] = CsvRowConverter.convert(fieldTypes.get(i), tokens[i]);
}
return (T) new Record(objects);
} catch (IOException e) {
System.out.println(e.getMessage());
}
throw new IllegalStateException(String.format("Error while parsing CSV file %s at line %s", sourcePath, s));
}
@Override
public List<ChannelDescriptor> getSupportedInputChannels(int index) {
return Collections.singletonList(FileChannel.HDFS_TSV_DESCRIPTOR);
}
@Override
public List<ChannelDescriptor> getSupportedOutputChannels(int index) {
assert index <= this.getNumOutputs() || (index == 0 && this.getNumOutputs() == 0);
return Collections.singletonList(StreamChannel.DESCRIPTOR);
}
/**
* Copied from {@link FileUtils} as a quick work around to read CSV file after skipping
* header row.
*
* Creates a {@link Stream} of a lines of the file.
*
* @param path of the file
* @return the {@link Stream}
*/
private static Stream<String> streamLines(String path) {
final FileSystem fileSystem = FileSystems.getFileSystem(path).orElseThrow(
() -> new IllegalStateException(String.format("No file system found for %s", path))
);
try {
Iterator<String> lineIterator = createLineIterator(fileSystem, path);
lineIterator.next(); // skip header row
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(lineIterator, 0), false);
} catch (IOException e) {
throw new WayangException(String.format("%s failed to read %s.", FileUtils.class, path), e);
}
}
/**
* Creates an {@link Iterator} over the lines of a given {@code path} (that resides in the given {@code fileSystem}).
*/
private static Iterator<String> createLineIterator(FileSystem fileSystem, String path) throws IOException {
final BufferedReader reader = new BufferedReader(new InputStreamReader(fileSystem.open(path), "UTF-8"));
return new Iterator<String>() {
String next;
{
this.advance();
}
private void advance() {
try {
this.next = reader.readLine();
} catch (IOException e) {
this.next = null;
throw new UncheckedIOException(e);
} finally {
if (this.next == null) {
IOUtils.closeQuietly(reader);
}
}
}
@Override
public boolean hasNext() {
return this.next != null;
}
@Override
public String next() {
assert this.hasNext();
final String returnValue = this.next;
this.advance();
return returnValue;
}
};
}
}
2b1aef4e9a7503c7e7f9987af1737a27fe565f78
- Ngôn ngữ chính
- Java
- Star
- 284
- Fork
- 147
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/wayang
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
JavaReservoirSampleOperator returns the whole input when the dataset size is unknownCó thể đã có người làm @sasmith-14 đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/wayang#884 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Record.compareTo() throws ClassCastException when comparing recordsCó thể đã có người làm @harshitsingh070 đã nhận 69 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Unused parameter in function ProjectionDescriptor.createPojoJavaImplementation()Có thể đã có người làm @AliRana30 đã nhận 77 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/wayang#732 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
DISCLAIMER and some "(incubating)" references are still around after graduationCó thể đã có người làm @sasmith-14 đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
apache/wayang#895 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của apache/wayang
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
jenkins-infra/plugin-modernizer-tool#2070 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Event search answers 500 when calendars, attendees or organizers holds a null elementCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởai-driven-qa bug Minor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
linagora/twake-calendar-side-service#1615 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
eclipse-tradista/tradista#371 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Failed to start Rescue missionĐang mởcritical
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
mars-sim/mars-sim#2199 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG-02] Endpoints /assistente/relatorio/*/preview retornam 404 ("Ver na tela" dos relatórios)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
projeto-ong-amar/projeto-ong-amar-backend#26 ·
Maintainer thường phản hồi trong vòng 1 ngày