Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void runInternal() throws HiveSQLException {
setState(OperationState.RUNNING);
try {
String command = getStatement().trim();
String[] tokens = statement.split("\\s");
String[] tokens = command.split("\\s");
String commandArgs = command.substring(tokens[0].length()).trim();

CommandProcessorResponse response = commandProcessor.run(commandArgs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.apache.hive.service.cli.operation;

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.processors.CommandProcessor;
import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.cli.session.HiveSession;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import java.io.File;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestHiveCommandOperation {

@Test
public void testRunInternalSetsCorrectArgumentsForUntrimmedInput() throws HiveSQLException {

HiveConf conf = new HiveConf(TestHiveCommandOperation.class);
File tmpFile = new File("/dev/null");

HiveSession mockHiveSession = mock(HiveSession.class);
SessionState mockSessionState = mock(SessionState.class);
CommandProcessor mockCommandProcessor = mock(CommandProcessor.class);

ArgumentCaptor<String> commandArgsCaptor = ArgumentCaptor.forClass(String.class);

when(mockHiveSession.getHiveConf()).thenReturn(conf);
when(mockHiveSession.getSessionState()).thenReturn(mockSessionState);
when(mockSessionState.getTmpOutputFile()).thenReturn(tmpFile);
when(mockSessionState.getTmpErrOutputFile()).thenReturn(tmpFile);
when(mockCommandProcessor.run(commandArgsCaptor.capture())).thenReturn(new CommandProcessorResponse(0));

HiveCommandOperation hiveCommandOperation = new HiveCommandOperation(mockHiveSession,
" set a = b", mockCommandProcessor, null);
hiveCommandOperation.runInternal();

String commandArgs = commandArgsCaptor.getValue();
assertEquals("a = b", commandArgs);
}
}