<commit_before>package com.inmobi.grill.hivecommand.service;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;

import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.cli.OperationHandle;
import org.apache.hive.service.cli.RowSet;
import org.apache.hive.service.cli.thrift.TRow;
import org.glassfish.jersey.media.multipart.FormDataParam;

import com.inmobi.grill.api.GrillSessionHandle;
import com.inmobi.grill.client.api.APIResult;
import com.inmobi.grill.client.api.QueryConf;
import com.inmobi.grill.client.api.StringList;
import com.inmobi.grill.exception.GrillException;
import com.inmobi.grill.service.GrillService;
import com.inmobi.grill.service.GrillServices;

@Path("/session")
public class CommandResource {
  private HiveCommandService commandService;

  @GET
  @Produces({MediaType.TEXT_PLAIN})
  public String getMessage() {
    return "Hello World! from command";
  }

  public CommandResource() throws GrillException {
    commandService = (HiveCommandService)GrillServices.get().getService("command");
  }

  @POST
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
  public GrillSessionHandle openSession(@FormDataParam("username") String username,
      @FormDataParam("password") String password,
      @FormDataParam("sessionconf") QueryConf sessionconf) {
    try {
      return new GrillSessionHandle(commandService.openSession(username, password, sessionconf.getProperties()));
    } catch (GrillException e) {
      throw new WebApplicationException(e);
    }
  }

  @DELETE
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
  public APIResult closeSession(@QueryParam("sessionid") GrillSessionHandle sessionid) {
    try {
      commandService.closeSession(sessionid.getSessionHandle());
    } catch (GrillException e) {
      throw new WebApplicationException(e);
    }
    return new APIResult(APIResult.Status.SUCCEEDED,
        "Close session with id" + sessionid.getSessionHandle() + "succeeded");
  }

  @PUT
  @Path("resources/add")
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})<commit_msg>Allow empty default value for sessionconf<commit_after>package com.inmobi.grill.hivecommand.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;

import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.cli.OperationHandle;
import org.apache.hive.service.cli.RowSet;
import org.apache.hive.service.cli.thrift.TRow;
import org.glassfish.jersey.media.multipart.FormDataParam;

import com.inmobi.grill.api.GrillSessionHandle;
import com.inmobi.grill.client.api.APIResult;
import com.inmobi.grill.client.api.QueryConf;
import com.inmobi.grill.client.api.StringList;
import com.inmobi.grill.exception.GrillException;
import com.inmobi.grill.service.GrillService;
import com.inmobi.grill.service.GrillServices;

@Path("/session")
public class CommandResource {
  private HiveCommandService commandService;

  @GET
  @Produces({MediaType.TEXT_PLAIN})
  public String getMessage() {
    return "Hello World! from command";
  }

  public CommandResource() throws GrillException {
    commandService = (HiveCommandService)GrillServices.get().getService("command");
  }

  @POST
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
  public GrillSessionHandle openSession(@FormDataParam("username") String username,
      @FormDataParam("password") String password,
      @DefaultValue("<conf/>") @FormDataParam("sessionconf") QueryConf sessionconf) {
    try {
      Map<String, String> conf;
      if (sessionconf != null) {
        conf = sessionconf.getProperties();
      } else{
        conf = new HashMap<String, String>();
      }
      return new GrillSessionHandle(commandService.openSession(username, password, conf));
    } catch (GrillException e) {
      throw new WebApplicationException(e);
    }
  }

  @DELETE
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
  public APIResult closeSession(@QueryParam("sessionid") GrillSessionHandle sessionid) {
    try {
      commandService.closeSession(sessionid.getSessionHandle());
    } catch (GrillException e) {
      throw new WebApplicationException(e);
    }
    return new APIResult(APIResult.Status.SUCCEEDED,
        "Close session with id" + sessionid.getSessionHandle() + "succeeded");
  }

  @PUT
  @Path("resources/add")
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
{'fraction_non_alphanumeric': 0.11616810423930997, 'fraction_numerical': 0.0, 'mean_word_length': 5.144306651634724, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1223439', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1739, 'n_words': 292}