Java Code Examples for com.klarna.hiverunner.annotations.HiveSQL

The following examples show how to use com.klarna.hiverunner.annotations.HiveSQL. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flink   Source File: FlinkStandaloneHiveRunner.java    License: Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 2
Source Project: flink   Source File: FlinkStandaloneHiveRunner.java    License: Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 3
Source Project: HiveRunner   Source File: HiveRunnerCore.java    License: Apache License 2.0 5 votes vote down vote up
private HiveShellField loadScriptUnderTest(Object testCaseInstance, HiveShellBuilder hiveShellBuilder) {
  try {
    Set<Field> fields = ReflectionUtils.getAllFields(testCaseInstance.getClass(), withAnnotation(HiveSQL.class));

    Preconditions.checkState(fields.size() == 1, "Exact one field should to be annotated with @HiveSQL");

    Field field = fields.iterator().next();
    List<Path> scriptPaths = new ArrayList<>();
    HiveSQL annotation = field.getAnnotation(HiveSQL.class);
    for (String scriptFilePath : annotation.files()) {
      Path file = Paths.get(Resources.getResource(scriptFilePath).toURI());
      assertFileExists(file);
      scriptPaths.add(file);
    }

    Charset charset = annotation.encoding().equals("") ?
        Charset.defaultCharset() : Charset.forName(annotation.encoding());

    boolean isAutoStart = annotation.autoStart();

    hiveShellBuilder.setScriptsUnderTest(scriptPaths, charset);

    return new HiveShellField() {
      @Override
      public void setShell(HiveShell shell) {
        ReflectionUtils.setField(testCaseInstance, 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);
  }
}