Skip to content

Commit

Permalink
[KYUUBI #6506] kyuubi-beeline supports --conf
Browse files Browse the repository at this point in the history
# 🔍 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

7a81455 [Bruce Wong] fix code style.
8d1fec2 [Bruce Wong] delete some spaces.
d64505d [Bruce Wong] [FEATURE] kyuubi-beeline supports --conf.

Authored-by: Bruce Wong <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
  • Loading branch information
BruceWong96 authored and pan3793 committed Jun 27, 2024
1 parent 845f6c6 commit 28a1c73
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/client/cli/kyuubi_beeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]";

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -671,7 +681,8 @@ private void processBeeLineOpt(final String arg) {
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));
}
Expand Down Expand Up @@ -751,6 +762,11 @@ private boolean connectUsingArgs(BeelineParser beelineParser, CommandLine cl) {
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");
Expand Down
1 change: 1 addition & 0 deletions kyuubi-hive-beeline/src/main/resources/BeeLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void testQueryScripts() throws Exception {
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();
Expand All @@ -231,14 +231,20 @@ public void testHiveConfAndVars() throws Exception {
"--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"));
Assert.assertTrue(bl.getOpts().getHiveConfVariables().get("a").equals("avalue"));
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
Expand Down

0 comments on commit 28a1c73

Please sign in to comment.