forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-14580][hive] add HiveModuleFactory, HiveModuleDescriptor, and …
…HiveModuleDescriptorValidator add HiveModuleFactory, HiveModuleDescriptor, and HiveModuleDescriptorValidator for HiveModule. This closes apache#10092.
- Loading branch information
Showing
5 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleDescriptor.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,57 @@ | ||
/* | ||
* 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:https://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.module.hive; | ||
|
||
import org.apache.flink.table.descriptors.DescriptorProperties; | ||
import org.apache.flink.table.descriptors.ModuleDescriptor; | ||
import org.apache.flink.util.StringUtils; | ||
|
||
import java.util.Map; | ||
|
||
import static org.apache.flink.table.module.hive.HiveModuleDescriptorValidator.MODULE_HIVE_VERSION; | ||
import static org.apache.flink.table.module.hive.HiveModuleDescriptorValidator.MODULE_TYPE_HIVE; | ||
import static org.apache.flink.util.Preconditions.checkArgument; | ||
|
||
/** | ||
* Module descriptor for {@link HiveModule}. | ||
*/ | ||
public class HiveModuleDescriptor extends ModuleDescriptor { | ||
private String hiveVersion; | ||
|
||
public HiveModuleDescriptor() { | ||
super(MODULE_TYPE_HIVE); | ||
} | ||
|
||
public HiveModuleDescriptor hiveVersion(String hiveVersion) { | ||
checkArgument(!StringUtils.isNullOrWhitespaceOnly(hiveVersion)); | ||
this.hiveVersion = hiveVersion; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected Map<String, String> toModuleProperties() { | ||
final DescriptorProperties properties = new DescriptorProperties(); | ||
|
||
if (hiveVersion != null) { | ||
properties.putString(MODULE_HIVE_VERSION, hiveVersion); | ||
} | ||
|
||
return properties.asMap(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleDescriptorValidator.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,37 @@ | ||
/* | ||
* 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:https://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.module.hive; | ||
|
||
import org.apache.flink.table.descriptors.DescriptorProperties; | ||
import org.apache.flink.table.descriptors.ModuleDescriptorValidator; | ||
|
||
/** | ||
* Validator for {@link HiveModuleDescriptor}. | ||
*/ | ||
public class HiveModuleDescriptorValidator extends ModuleDescriptorValidator { | ||
public static final String MODULE_TYPE_HIVE = "hive"; | ||
public static final String MODULE_HIVE_VERSION = "hive-version"; | ||
|
||
@Override | ||
public void validate(DescriptorProperties properties) { | ||
super.validate(properties); | ||
properties.validateValue(MODULE_TYPE, MODULE_TYPE_HIVE, false); | ||
properties.validateString(MODULE_HIVE_VERSION, true, 1); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...nk-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleFactory.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,71 @@ | ||
/* | ||
* 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:https://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.module.hive; | ||
|
||
import org.apache.flink.table.catalog.hive.client.HiveShimLoader; | ||
import org.apache.flink.table.descriptors.DescriptorProperties; | ||
import org.apache.flink.table.factories.ModuleFactory; | ||
import org.apache.flink.table.module.Module; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.flink.table.descriptors.ModuleDescriptorValidator.MODULE_TYPE; | ||
import static org.apache.flink.table.module.hive.HiveModuleDescriptorValidator.MODULE_HIVE_VERSION; | ||
import static org.apache.flink.table.module.hive.HiveModuleDescriptorValidator.MODULE_TYPE_HIVE; | ||
|
||
/** | ||
* Factory for {@link HiveModule}. | ||
*/ | ||
public class HiveModuleFactory implements ModuleFactory { | ||
|
||
@Override | ||
public Module createModule(Map<String, String> properties) { | ||
final DescriptorProperties descProperties = getValidatedProperties(properties); | ||
|
||
final String hiveVersion = descProperties.getOptionalString(MODULE_HIVE_VERSION) | ||
.orElse(HiveShimLoader.getHiveVersion()); | ||
|
||
return new HiveModule(hiveVersion); | ||
} | ||
|
||
private static DescriptorProperties getValidatedProperties(Map<String, String> properties) { | ||
final DescriptorProperties descriptorProperties = new DescriptorProperties(true); | ||
descriptorProperties.putProperties(properties); | ||
|
||
new HiveModuleDescriptorValidator().validate(descriptorProperties); | ||
|
||
return descriptorProperties; | ||
} | ||
|
||
@Override | ||
public Map<String, String> requiredContext() { | ||
Map<String, String> context = new HashMap<>(); | ||
context.put(MODULE_TYPE, MODULE_TYPE_HIVE); | ||
|
||
return context; | ||
} | ||
|
||
@Override | ||
public List<String> supportedProperties() { | ||
return new ArrayList<>(); | ||
} | ||
} |
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
...ector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleDescriptorTest.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:https://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.module.hive; | ||
|
||
import org.apache.flink.table.descriptors.Descriptor; | ||
import org.apache.flink.table.descriptors.DescriptorTestBase; | ||
import org.apache.flink.table.descriptors.DescriptorValidator; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Tests for {@link HiveModuleDescriptor}. | ||
*/ | ||
public class HiveModuleDescriptorTest extends DescriptorTestBase { | ||
|
||
@Override | ||
protected List<Descriptor> descriptors() { | ||
final Descriptor descriptor = new HiveModuleDescriptor(); | ||
|
||
return Arrays.asList(descriptor); | ||
} | ||
|
||
@Override | ||
protected List<Map<String, String>> properties() { | ||
final Map<String, String> props1 = new HashMap<>(); | ||
props1.put("type", "hive"); | ||
|
||
return Arrays.asList(props1); | ||
} | ||
|
||
@Override | ||
protected DescriptorValidator validator() { | ||
return new HiveModuleDescriptorValidator(); | ||
} | ||
} |