use of com.klarna.hiverunner.annotations.HiveSQL in project flink by apache.
the class FlinkEmbeddedHiveRunner method loadScriptsUnderTest.
private HiveShellField loadScriptsUnderTest(final Class testClass, HiveShellBuilder hiveShellBuilder) {
try {
Set<Field> fields = ReflectionUtils.getAllFields(testClass, withAnnotation(HiveSQL.class));
Preconditions.checkState(fields.size() == 1, "Exactly one field should to be annotated with @HiveSQL");
final Field field = fields.iterator().next();
List<Path> scripts = new ArrayList<>();
HiveSQL annotation = field.getAnnotation(HiveSQL.class);
for (String scriptFilePath : annotation.files()) {
Path file = Paths.get(Resources.getResource(scriptFilePath).toURI());
Preconditions.checkState(Files.exists(file), "File " + file + " does not exist");
scripts.add(file);
}
Charset charset = annotation.encoding().equals("") ? Charset.defaultCharset() : Charset.forName(annotation.encoding());
final boolean isAutoStart = annotation.autoStart();
hiveShellBuilder.setScriptsUnderTest(scripts, charset);
return new HiveShellField() {
@Override
public void setShell(HiveShell shell) {
ReflectionUtils.setStaticField(testClass, field.getName(), shell);
}
@Override
public boolean isAutoStart() {
return isAutoStart;
}
};
} catch (Throwable t) {
throw new IllegalArgumentException("Failed to init field annotated with @HiveSQL: " + t.getMessage(), t);
}
}