[KYUUBI #6506] kyuubi-beeline supports --conf

# 🔍 Description
## Issue References 🔗

This pull request fixes #6506

## Describe Your Solution 🔧

Set the alias `--conf` to `--hiveconf`.

## Types of changes 🔖

- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Test Plan 🧪

#### Behavior Without This Pull Request ⚰️
```
# use --hiveconf or --hivevar to set some configurations
kyuubi-beeline -u 'jdbc:kyuubi://kyuubi:10009/' \
    --hiveconf kyuubi.operation.result.format=arrow \
    --hiveconf kyuubi.operation.incremental.collect=true-f \
    --hivevar app_name=xxx \
    xxx.sql
```

#### Behavior With This Pull Request 🎉
```
# use --conf to set some configurations
kyuubi-beeline -u 'jdbc:kyuubi://kyuubi:10009/' \
    --conf kyuubi.operation.result.format=arrow \
    --conf kyuubi.operation.incremental.collect=true-f \
    --conf app_name=xxx \
    xxx.sql
```

#### Related Unit Tests

---

# Checklist 📝

- [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)

**Be nice. Be informative.**

Closes #6511 from BruceWong96/support-beeline-conf.

Closes #6506

7a81455d8 [Bruce Wong] fix code style.
8d1fec242 [Bruce Wong] delete some spaces.
d64505dd7 [Bruce Wong] [FEATURE] kyuubi-beeline supports --conf.

Authored-by: Bruce Wong <603334301@qq.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Bruce Wong 2024-06-27 22:12:25 +08:00 committed by Cheng Pan
parent 845f6c63a9
commit 28a1c735af
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
4 changed files with 27 additions and 3 deletions

View File

@ -49,6 +49,7 @@ Options:
-f <exec file> Script file that should be executed.
-w, --password-file <file> The password file to read password from.
--hiveconf property=value Use value for given property.
--conf property=value Alias of --hiveconf.
--hivevar name=value Hive variable name and value.
This is Hive specific settings in which variables
can be set at session level and referenced in Hive

View File

@ -159,6 +159,7 @@ public class BeeLine implements Closeable {
private static final String HIVE_VAR_PREFIX = "--hivevar";
private static final String HIVE_CONF_PREFIX = "--hiveconf";
private static final String CONF_PREFIX = "--conf";
private static final String PROP_FILE_PREFIX = "--property-file";
static final String PASSWD_MASK = "[passwd stripped]";
@ -377,6 +378,15 @@ public class BeeLine implements Closeable {
.withDescription("Use value for given property")
.create());
// conf option --conf
options.addOption(
OptionBuilder.withValueSeparator()
.hasArgs(2)
.withArgName("property=value")
.withLongOpt("conf")
.withDescription("Alias of --hiveconf")
.create());
// --property-file <file>
options.addOption(
OptionBuilder.hasArg()
@ -671,7 +681,8 @@ public class BeeLine implements Closeable {
private boolean isBeeLineOpt(String arg) {
return arg.startsWith("--")
&& !(HIVE_VAR_PREFIX.equals(arg)
|| (HIVE_CONF_PREFIX.equals(arg))
|| HIVE_CONF_PREFIX.equals(arg)
|| CONF_PREFIX.equals(arg)
|| "--help".equals(arg)
|| PROP_FILE_PREFIX.equals(arg));
}
@ -751,6 +762,11 @@ public class BeeLine implements Closeable {
setHiveConfVar(key, hiveConfs.getProperty(key));
}
Properties confs = cl.getOptionProperties("conf");
for (String key : confs.stringPropertyNames()) {
setHiveConfVar(key, confs.getProperty(key));
}
driver = cl.getOptionValue("d");
auth = cl.getOptionValue("a");
user = cl.getOptionValue("n");

View File

@ -169,6 +169,7 @@ Options:\n\
\ -f <exec file> Script file that should be executed.\n\
\ -w, --password-file <file> The password file to read password from.\n\
\ --hiveconf property=value Use value for given property.\n\
\ --conf property=value Alias of --hiveconf. \n\
\ --hivevar name=value Hive variable name and value.\n\
\ This is Hive specific settings in which variables\n\
\ can be set at session level and referenced in Hive\n\

View File

@ -210,7 +210,7 @@ public class TestBeelineArgParsing {
Assert.assertTrue(bl.queries.contains("select2"));
}
/** Test setting hive conf and hive vars with --hiveconf and --hivevar */
/** Test setting hive conf and hive vars with --hiveconf, --hivevar and --conf */
@Test
public void testHiveConfAndVars() throws Exception {
TestBeeline bl = new TestBeeline();
@ -231,7 +231,11 @@ public class TestBeelineArgParsing {
"--hivevar",
"c=cvalue",
"--hivevar",
"d=dvalue"
"d=dvalue",
"--conf",
"e=evalue",
"--conf",
"f=fvalue"
};
Assert.assertEquals(0, bl.initArgs(args));
Assert.assertTrue(bl.connectArgs.equals("url name password driver"));
@ -239,6 +243,8 @@ public class TestBeelineArgParsing {
Assert.assertTrue(bl.getOpts().getHiveConfVariables().get("b").equals("bvalue"));
Assert.assertTrue(bl.getOpts().getHiveVariables().get("c").equals("cvalue"));
Assert.assertTrue(bl.getOpts().getHiveVariables().get("d").equals("dvalue"));
Assert.assertTrue(bl.getOpts().getHiveConfVariables().get("e").equals("evalue"));
Assert.assertTrue(bl.getOpts().getHiveConfVariables().get("f").equals("fvalue"));
}
@Test