-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][core] support arrow transfers data to SeatunnelRow in arrow…
… format
- Loading branch information
Showing
26 changed files
with
1,515 additions
and
1,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...va/org/apache/seatunnel/connectors/seatunnel/common/source/arrow/converter/Converter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.common.source.arrow.converter; | ||
|
||
import org.apache.seatunnel.shade.org.apache.arrow.vector.FieldVector; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.types.Types; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public interface Converter<T extends FieldVector> { | ||
|
||
String ARRAY_KEY = "ARRAY"; | ||
String MAP_KEY = "KEY"; | ||
String MAP_VALUE = "VALUE"; | ||
|
||
Object convert(int rowIndex, T fieldVector); | ||
|
||
default Object convert(int rowIndex, T fieldVector, Map<String, Function> genericsConverters) { | ||
throw new UnsupportedOperationException("Unsupported generics convert"); | ||
} | ||
|
||
boolean support(Types.MinorType type); | ||
} |
34 changes: 34 additions & 0 deletions
34
...apache/seatunnel/connectors/seatunnel/common/source/arrow/converter/DefaultConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.common.source.arrow.converter; | ||
|
||
import org.apache.seatunnel.shade.org.apache.arrow.vector.FieldVector; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.types.Types; | ||
|
||
public class DefaultConverter implements Converter<FieldVector> { | ||
|
||
@Override | ||
public Object convert(int rowIndex, FieldVector fieldVector) { | ||
return fieldVector.isNull(rowIndex) ? null : fieldVector.getObject(rowIndex); | ||
} | ||
|
||
@Override | ||
public boolean support(Types.MinorType type) { | ||
return false; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../seatunnel/connectors/seatunnel/common/source/arrow/converter/FixedSizeListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.common.source.arrow.converter; | ||
|
||
import org.apache.seatunnel.shade.org.apache.arrow.vector.complex.FixedSizeListVector; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.types.Types; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class FixedSizeListConverter implements Converter<FixedSizeListVector> { | ||
@Override | ||
public Object convert(int rowIndex, FixedSizeListVector fieldVector) { | ||
return fieldVector.isNull(rowIndex) ? null : fieldVector.getObject(rowIndex); | ||
} | ||
|
||
@Override | ||
public Object convert( | ||
int rowIndex, | ||
FixedSizeListVector fieldVector, | ||
Map<String, Function> genericsConverters) { | ||
if (fieldVector.isNull(rowIndex)) { | ||
return null; | ||
} | ||
List<?> listData = fieldVector.getObject(rowIndex); | ||
Function converter = genericsConverters.get(ARRAY_KEY); | ||
return listData.stream() | ||
.map( | ||
item -> { | ||
if (item instanceof LocalDateTime) { | ||
LocalDateTime localDateTime = | ||
((LocalDateTime) item) | ||
.atZone(ZoneOffset.UTC) | ||
.withZoneSameInstant(ZoneId.systemDefault()) | ||
.toLocalDateTime(); | ||
return converter.apply(localDateTime); | ||
} else { | ||
return converter.apply(item); | ||
} | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public boolean support(Types.MinorType type) { | ||
return Types.MinorType.FIXED_SIZE_LIST == type; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ache/seatunnel/connectors/seatunnel/common/source/arrow/converter/LargeListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.common.source.arrow.converter; | ||
|
||
import org.apache.seatunnel.shade.org.apache.arrow.vector.complex.LargeListVector; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.types.Types; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class LargeListConverter implements Converter<LargeListVector> { | ||
@Override | ||
public Object convert(int rowIndex, LargeListVector fieldVector) { | ||
return fieldVector.isNull(rowIndex) ? null : fieldVector.getObject(rowIndex); | ||
} | ||
|
||
@Override | ||
public Object convert( | ||
int rowIndex, LargeListVector fieldVector, Map<String, Function> genericsConverters) { | ||
if (fieldVector.isNull(rowIndex)) { | ||
return null; | ||
} | ||
if (fieldVector.isEmpty(rowIndex)) { | ||
return Collections.emptyList(); | ||
} | ||
List<?> listData = fieldVector.getObject(rowIndex); | ||
Function converter = genericsConverters.get(ARRAY_KEY); | ||
return listData.stream() | ||
.map( | ||
item -> { | ||
if (item instanceof LocalDateTime) { | ||
LocalDateTime localDateTime = | ||
((LocalDateTime) item) | ||
.atZone(ZoneOffset.UTC) | ||
.withZoneSameInstant(ZoneId.systemDefault()) | ||
.toLocalDateTime(); | ||
return converter.apply(localDateTime); | ||
} else { | ||
return converter.apply(item); | ||
} | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public boolean support(Types.MinorType type) { | ||
return Types.MinorType.LARGELIST == type; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...rg/apache/seatunnel/connectors/seatunnel/common/source/arrow/converter/ListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.common.source.arrow.converter; | ||
|
||
import org.apache.seatunnel.shade.org.apache.arrow.vector.complex.ListVector; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.types.Types; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class ListConverter implements Converter<ListVector> { | ||
@Override | ||
public Object convert(int rowIndex, ListVector fieldVector) { | ||
return fieldVector.isNull(rowIndex) ? null : fieldVector.getObject(rowIndex); | ||
} | ||
|
||
@Override | ||
public Object convert( | ||
int rowIndex, ListVector fieldVector, Map<String, Function> genericsConverters) { | ||
if (fieldVector.isNull(rowIndex)) { | ||
return null; | ||
} | ||
if (fieldVector.isEmpty(rowIndex)) { | ||
return Collections.emptyList(); | ||
} | ||
List<?> listData = fieldVector.getObject(rowIndex); | ||
Function converter = genericsConverters.get(ARRAY_KEY); | ||
return listData.stream() | ||
.map( | ||
item -> { | ||
if (item instanceof LocalDateTime) { | ||
LocalDateTime localDateTime = | ||
((LocalDateTime) item) | ||
.atZone(ZoneOffset.UTC) | ||
.withZoneSameInstant(ZoneId.systemDefault()) | ||
.toLocalDateTime(); | ||
return converter.apply(localDateTime); | ||
} else { | ||
return converter.apply(item); | ||
} | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public boolean support(Types.MinorType type) { | ||
return Types.MinorType.LIST == type; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...org/apache/seatunnel/connectors/seatunnel/common/source/arrow/converter/MapConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.common.source.arrow.converter; | ||
|
||
import org.apache.seatunnel.shade.org.apache.arrow.vector.complex.MapVector; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.complex.impl.UnionMapReader; | ||
import org.apache.seatunnel.shade.org.apache.arrow.vector.types.Types; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class MapConverter implements Converter<MapVector> { | ||
@Override | ||
public Object convert(int rowIndex, MapVector fieldVector) { | ||
return fieldVector.isNull(rowIndex) ? null : fieldVector.getObject(rowIndex); | ||
} | ||
|
||
@Override | ||
public Object convert( | ||
int rowIndex, MapVector fieldVector, Map<String, Function> genericsConverters) { | ||
UnionMapReader reader = fieldVector.getReader(); | ||
reader.setPosition(rowIndex); | ||
Map<Object, Object> mapValue = new HashMap<>(); | ||
Function keyConverter = genericsConverters.get(MAP_KEY); | ||
Function valueConverter = genericsConverters.get(MAP_VALUE); | ||
while (reader.next()) { | ||
Object key = keyConverter.apply(processTimeZone(reader.key().readObject())); | ||
Object value = valueConverter.apply(processTimeZone(reader.value().readObject())); | ||
mapValue.put(key, value); | ||
} | ||
return mapValue; | ||
} | ||
|
||
private Object processTimeZone(Object value) { | ||
if (value instanceof LocalDateTime) { | ||
return ((LocalDateTime) value) | ||
.atZone(ZoneOffset.UTC) | ||
.withZoneSameInstant(ZoneId.systemDefault()) | ||
.toLocalDateTime(); | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean support(Types.MinorType type) { | ||
return Types.MinorType.MAP == type; | ||
} | ||
} |
Oops, something went wrong.