static String substitute(Configuration conf, String expr) { return expr == null ? null : INSTANCE.substitute(conf, expr, 1); }
/** * The super method will handle with the case of substitutions for system variables, * hive conf variables and env variables. In this method, it will retrieve the hive * variables using hiveVariableSource. * * @param conf * @param var * @return */ @Override protected String getSubstitute(Configuration conf, String var) { String val = super.getSubstitute(conf, var); if (val == null && hiveVariableSource != null) { Map<String, String> vars = hiveVariableSource.getHiveVariable(); if (var.startsWith(HIVEVAR_PREFIX)) { val = vars.get(var.substring(HIVEVAR_PREFIX.length())); } else { val = vars.get(var); } } return val; }
protected String getSubstitute(Configuration conf, String variableName) { try { if (variableName.startsWith(SYSTEM_PREFIX)) { String propertyName = variableName.substring(SYSTEM_PREFIX.length()); String originalValue = System.getProperty(propertyName); return applyCoercion(variableName, originalValue); } } catch(SecurityException se) { l4j.warn("Unexpected SecurityException in Configuration", se); } if (variableName.startsWith(ENV_PREFIX)) { return System.getenv(variableName.substring(ENV_PREFIX.length())); } if (conf != null && variableName.startsWith(HIVECONF_PREFIX)) { return conf.get(variableName.substring(HIVECONF_PREFIX.length())); } return null; }
static String substitute(Configuration conf, String expr) { return expr == null ? null : new SystemVariables().substitute(conf, expr, 1); }
static String substitute(String expr) { return expr == null ? null : new SystemVariables().substitute(null, expr, 1); }
static String substitute(String expr) { return expr == null ? null : INSTANCE.substitute(null, expr, 1); }
String group = match.group(); String var = group.substring(2, group.length() - 1); // remove ${ .. } String substitute = getSubstitute(conf, var); if (substitute == null) {
protected String getSubstitute(Configuration conf, String variableName) { try { if (variableName.startsWith(SYSTEM_PREFIX)) { String propertyName = variableName.substring(SYSTEM_PREFIX.length()); String originalValue = System.getProperty(propertyName); return applyCoercion(variableName, originalValue); } } catch(SecurityException se) { l4j.warn("Unexpected SecurityException in Configuration", se); } if (variableName.startsWith(ENV_PREFIX)) { return System.getenv(variableName.substring(ENV_PREFIX.length())); } if (conf != null && variableName.startsWith(HIVECONF_PREFIX)) { return conf.get(variableName.substring(HIVECONF_PREFIX.length())); } return null; }
this.valClass = String.class; this.valType = VarType.STRING; this.defaultStrVal = SystemVariables.substitute((String)defaultVal); this.defaultIntVal = -1; this.defaultLongVal = -1;
/** * The super method will handle with the case of substitutions for system variables, * hive conf variables and env variables. In this method, it will retrieve the hive * variables using hiveVariableSource. * * @param conf * @param var * @return */ @Override protected String getSubstitute(Configuration conf, String var) { String val = super.getSubstitute(conf, var); if (val == null && hiveVariableSource != null) { Map<String, String> vars = hiveVariableSource.getHiveVariable(); if (var.startsWith(HIVEVAR_PREFIX)) { val = vars.get(var.substring(HIVEVAR_PREFIX.length())); } else { val = vars.get(var); } } return val; }
@Test public void test_RelativeJavaIoTmpDir_CoercedTo_AbsolutePath() { FileSystem localFileSystem = new LocalFileSystem(); String systemJavaIoTmpDir = makeVarName(SYSTEM, "java.io.tmpdir"); System.setProperty("java.io.tmpdir", "./relativePath"); Path relativePath = new Path(localFileSystem.getWorkingDirectory(), "./relativePath"); assertEquals(relativePath.toString(), SystemVariables.substitute(systemJavaIoTmpDir)); System.setProperty("java.io.tmpdir", "this/is/a/relative/path"); Path thisIsARelativePath= new Path(localFileSystem.getWorkingDirectory(), "this/is/a/relative/path"); assertEquals(thisIsARelativePath.toString(), SystemVariables.substitute(systemJavaIoTmpDir)); }
@Override protected String getSubstitute(Configuration conf, String var) { String val = super.getSubstitute(conf, var); if (val == null && SessionState.get() != null) { Map<String,String> vars = SessionState.get().getHiveVariables(); if (var.startsWith(HIVEVAR_PREFIX)) { val = vars.get(var.substring(HIVEVAR_PREFIX.length())); } else { val = vars.get(var); } } return val; }
@Test public void test_RelativePathWithNoCoercion_NotChanged() { FileSystem localFileSystem = new LocalFileSystem(); String systemJavaIoTmpDir = makeVarName(SYSTEM, "java.io._NOT_tmpdir"); System.setProperty("java.io._NOT_tmpdir", "this/is/an/relative/path"); Path relativePath = new Path("this/is/an/relative/path"); assertEquals(relativePath.toString(), SystemVariables.substitute(systemJavaIoTmpDir)); }
String group = match.group(); String var = group.substring(2, group.length() - 1); // remove ${ .. } String substitute = getSubstitute(conf, var); if (substitute == null) {
@Test public void test_AbsoluteJavaIoTmpDir_NotChanged() { FileSystem localFileSystem = new LocalFileSystem(); String systemJavaIoTmpDir = makeVarName(SYSTEM, "java.io.tmpdir"); System.setProperty("java.io.tmpdir", "file:/this/is/an/absolute/path"); Path absolutePath = new Path("file:/this/is/an/absolute/path"); assertEquals(absolutePath.toString(), SystemVariables.substitute(systemJavaIoTmpDir)); }
String group = match.group(); String var = group.substring(2, group.length() - 1); // remove ${ .. } String substitute = getSubstitute(conf, var); if (substitute == null) {
@Test public void test_EmptyJavaIoTmpDir_NotChanged() { FileSystem localFileSystem = new LocalFileSystem(); String systemJavaIoTmpDir = makeVarName(SYSTEM, "java.io.tmpdir"); System.setProperty("java.io.tmpdir", ""); assertEquals("", SystemVariables.substitute(systemJavaIoTmpDir)); } }
static String substitute(String expr) { return expr == null ? null : INSTANCE.substitute(null, expr, 1); }
static String substitute(Configuration conf, String expr) { return expr == null ? null : INSTANCE.substitute(conf, expr, 1); }
this.valClass = String.class; this.valType = VarType.STRING; this.defaultStrVal = SystemVariables.substitute((String)defaultVal); this.defaultIntVal = -1; this.defaultLongVal = -1;