Skip to content

Commit 7c8bee4

Browse files
committed
Add Sedona Flink SQL module
1 parent d6ea87c commit 7c8bee4

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.sedona.flink;
20+
21+
import java.util.Arrays;
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
import java.util.Optional;
25+
import java.util.Set;
26+
import java.util.stream.Collectors;
27+
import java.util.stream.Stream;
28+
import org.apache.flink.table.functions.FunctionDefinition;
29+
import org.apache.flink.table.module.Module;
30+
31+
public class SedonaModule implements Module {
32+
33+
private Map<String, FunctionDefinition> functions = new HashMap<>();
34+
35+
public SedonaModule() {
36+
Stream<FunctionDefinition> funcs = Arrays.stream(Catalog.getFuncs());
37+
Stream<FunctionDefinition> predicates = Arrays.stream(Catalog.getPredicates());
38+
39+
this.functions =
40+
Stream.concat(funcs, predicates)
41+
.collect(Collectors.toMap(func -> func.getClass().getSimpleName().toLowerCase(), func -> func));
42+
}
43+
44+
@Override
45+
public Set<String> listFunctions() {
46+
return functions.keySet();
47+
}
48+
49+
@Override
50+
public Optional<FunctionDefinition> getFunctionDefinition(String name) {
51+
return Optional.ofNullable(functions.get(name.toLowerCase()));
52+
}
53+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.sedona.flink;
20+
21+
import java.util.Collections;
22+
import java.util.Set;
23+
import org.apache.flink.configuration.ConfigOption;
24+
import org.apache.flink.table.factories.ModuleFactory;
25+
import org.apache.flink.table.module.Module;
26+
27+
public class SedonaModuleFactory implements ModuleFactory {
28+
29+
public static final String IDENTIFIER = "sedona";
30+
31+
@Override
32+
public Module createModule(Context context) {
33+
return new SedonaModule();
34+
}
35+
36+
@Override
37+
public String factoryIdentifier() {
38+
return IDENTIFIER;
39+
}
40+
41+
@Override
42+
public Set<ConfigOption<?>> requiredOptions() {
43+
return Collections.emptySet();
44+
}
45+
46+
@Override
47+
public Set<ConfigOption<?>> optionalOptions() {
48+
return Collections.emptySet();
49+
}
50+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.apache.sedona.flink.SedonaModuleFactory

0 commit comments

Comments
 (0)