-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-36269][python] Remove usage about TableEnvironmentInternal#fro…
…mTableSource in python module (#25322)
- Loading branch information
1 parent
b700f1c
commit c3daf84
Showing
9 changed files
with
214 additions
and
48 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
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
54 changes: 54 additions & 0 deletions
54
flink-python/src/main/java/org/apache/flink/table/runtime/arrow/ByteArrayUtils.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,54 @@ | ||
/* | ||
* 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.flink.table.runtime.arrow; | ||
|
||
import org.apache.flink.annotation.Internal; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.util.Base64; | ||
|
||
/** A utility class for converting byte[][] to String and String to byte[][]. */ | ||
@Internal | ||
public class ByteArrayUtils { | ||
|
||
/** Convert byte[][] to String. */ | ||
public static String twoDimByteArrayToString(byte[][] byteArray) throws IOException { | ||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
ObjectOutputStream oos = new ObjectOutputStream(bos); | ||
oos.writeObject(byteArray); | ||
oos.flush(); | ||
byte[] serializedArray = bos.toByteArray(); | ||
|
||
return Base64.getEncoder().encodeToString(serializedArray); | ||
} | ||
|
||
/** Convert String to byte[][]. */ | ||
public static byte[][] stringToTwoDimByteArray(String str) | ||
throws IOException, ClassNotFoundException { | ||
byte[] bytes = Base64.getDecoder().decode(str); | ||
|
||
ByteArrayInputStream bis = new ByteArrayInputStream(bytes); | ||
ObjectInputStream ois = new ObjectInputStream(bis); | ||
return (byte[][]) ois.readObject(); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
...n/src/main/java/org/apache/flink/table/runtime/arrow/sources/ArrowTableSourceFactory.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,62 @@ | ||
/* | ||
* 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.flink.table.runtime.arrow.sources; | ||
|
||
import org.apache.flink.configuration.ConfigOption; | ||
import org.apache.flink.configuration.ReadableConfig; | ||
import org.apache.flink.table.connector.source.DynamicTableSource; | ||
import org.apache.flink.table.factories.DynamicTableSourceFactory; | ||
import org.apache.flink.table.factories.FactoryUtil; | ||
import org.apache.flink.table.types.DataType; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** Factory for creating configured instances of {@link ArrowTableSource}.. */ | ||
public class ArrowTableSourceFactory implements DynamicTableSourceFactory { | ||
|
||
public static final String IDENTIFIER = "python-arrow-source"; | ||
|
||
@Override | ||
public String factoryIdentifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Set<ConfigOption<?>> requiredOptions() { | ||
Set<ConfigOption<?>> options = new HashSet<>(); | ||
options.add(ArrowTableSourceOptions.DATA); | ||
return options; | ||
} | ||
|
||
@Override | ||
public Set<ConfigOption<?>> optionalOptions() { | ||
return new HashSet<>(); | ||
} | ||
|
||
@Override | ||
public DynamicTableSource createDynamicTableSource(Context context) { | ||
FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context); | ||
ReadableConfig tableOptions = helper.getOptions(); | ||
|
||
String data = tableOptions.get(ArrowTableSourceOptions.DATA); | ||
DataType dataType = context.getPhysicalRowDataType(); | ||
return new ArrowTableSource(dataType, data); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...n/src/main/java/org/apache/flink/table/runtime/arrow/sources/ArrowTableSourceOptions.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.flink.table.runtime.arrow.sources; | ||
|
||
import org.apache.flink.configuration.ConfigOption; | ||
import org.apache.flink.configuration.ConfigOptions; | ||
|
||
/** Table options for the {@link ArrowTableSource}. */ | ||
public class ArrowTableSourceOptions { | ||
|
||
public static final ConfigOption<String> DATA = | ||
ConfigOptions.key("data") | ||
.stringType() | ||
.noDefaultValue() | ||
.withDescription( | ||
"This is the data serialized by Arrow with a byte two-dimensional array. " | ||
+ "Note: The byte two-dimensional array is converted into a string using base64."); | ||
} |
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