text:
package org.apache.hive.streaming;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RawLocalFileSystem;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hive.cli.CliSessionState;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
import org.apache.hadoop.hive.ql.DriverFactory;
import org.apache.hadoop.hive.ql.IDriver;
import org.apache.hadoop.hive.ql.processors.CommandProcessorException;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.serde.serdeConstants;
import org.apache.thrift.TException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestStreamingDynamicPartitioning {
  private static final Logger LOG = LoggerFactory.getLogger(TestStreamingDynamicPartitioning.class);

  public static class RawFileSystem extends RawLocalFileSystem {
    private static final URI NAME;

    static {
      try {
        NAME = new URI("raw:///");
      } catch (URISyntaxException se) {
        throw new IllegalArgumentException("bad uri", se);
      }
    }

    @Override
    public URI getUri() {
      return NAME;
    }

    @Override
    public String getScheme() {
      return "raw";
    }

    @Override
    public FileStatus getFileStatus(Path path) throws IOException {
      File file = pathToFile(path);
      if (!file.exists()) {
        throw new FileNotFoundException("Cannot find " + path);
      }
      // get close enough
      short mod = 0;
      if (file.canRead()) {
        mod |= 0444;
      }
      if (file.canWrite()) {
        mod |= 0200;
      }
      if (file.canExecute()) {
        mod |= 0111;
      }
      return new FileStatus(file.length(), file.isDirectory(), 1, 1024,
        file.lastModified(), file.lastModified(),
        FsPermission.createImmutable(mod), "owen", "users", path);
    }
  }

  private final HiveConf conf;
  private IDriver driver;
  private final IMetaStoreClient msClient;

  private static final String COL1 = "id";
  private static final String COL2 = "msg";
  @Rule
  public TemporaryFolder dbFolder = new TemporaryFolder();

  // partitioned table
  private final static String dbName = "testing";
  private final static String tblName = "alerts";
  private final static String[] fieldNames = new String[]{COL1, COL2};
  private final static String[] colTypes = new String[]{serdeConstants.INT_TYPE_NAME, serdeConstants.STRING_TYPE_NAME};
  private final static String[] partNames = new String[]{"Continent", "Country"};
  private final static String[] bucketCols = new String[]{COL1};
  private final String loc1;

  // unpartitioned table
  private final static String dbName2 = "testing2";

  public TestStreamingDynamicPartitioning() throws Exception {
    conf = new HiveConf(this.getClass());
    conf.set("fs.raw.impl", RawFileSystem.class.getName());
    conf
      .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
        "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    TestTxnDbUtil.setConfValues(conf);
    conf.setBoolVar(HiveConf.ConfVars.METASTORE_EXECUTE_SET_UGI, true);
    conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, true);
    dbFolder.create();
    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.WAREHOUSE, "raw://" + dbFolder.newFolder("warehouse"));
    loc1 = dbFolder.newFolder(dbName + ".db").toString();

    //1) Start from a clean slate (metastore)
    TestTxnDbUtil.cleanDb(conf);
    TestTxnDbUtil.prepDb(conf);

    //2) obtain metastore clients
    msClient = new HiveMetaStoreClient(conf);
  }

  @Before
  public void setup() throws Exception {
    SessionState.start(new CliSessionState(conf));
    driver = DriverFactory.newDriver(conf);
    driver.setMaxRows(200002);//make sure Driver returns all results
    // drop and recreate the necessary databases and tables
    dropDB(msClient, dbName);

    createDbAndTable(driver, dbName, tblName, null, fieldNames, colTypes, bucketCols, partNames, loc1, 1);

    dropDB(msClient, dbName2);
    String loc2 = dbFolder.newFolder(dbName2 + ".db").toString();
    String loc3 = dbFolder.newFolder("testing5.db").toString();
    createStoreSales("testing5", loc3);

    runDDL(driver, "drop table testBucketing3.streamedtable");
    runDDL(driver, "drop table testBucketing3.finaltable");
    runDDL(driver, "drop table testBucketing3.nobucket");
  }

  @After
  public void cleanup() throws Exception {
    msClient.close();
    driver.close();
  }

  private void createStoreSales(String dbName, String loc) throws Exception {
    String dbUri = "raw://" + new Path(loc).toUri().toString();
    String tableLoc = dbUri + Path.SEPARATOR + "store_sales";

    boolean success = runDDL(driver, "create database IF NOT EXISTS " + dbName + " location '" + dbUri + "'");
    Assert.assertTrue(success);
    success = runDDL(driver, "use " + dbName);
    Assert.assertTrue(success);

    success = runDDL(driver, "drop table if exists store_sales");
    Assert.assertTrue(success);
    success = runDDL(driver, "create table store_sales\n" +
      "(\n" +
      "    ss_sold_date_sk           int,\n" +
      "    ss_sold_time_sk           int,\n" +
      "    ss_item_sk                int,\n" +
      "    ss_customer_sk            int,\n" +
      "    ss_cdemo_sk               int,\n" +
      "    ss_hdemo_sk               int,\n" +
      "    ss_addr_sk                int,\n" +
      "    ss_store_sk               int,\n" +
      "    ss_promo_sk               int,\n" +
      "    ss_ticket_number          int,\n" +
      "    ss_quantity               int,\n" +
      "    ss_wholesale_cost         decimal(7,2),\n" +
      "    ss_list_price             decimal(7,2),\n" +
      "    ss_sales_price            decimal(7,2),\n" +
      "    ss_ext_discount_amt       decimal(7,2),\n" +
      "    ss_ext_sales_price        decimal(7,2),\n" +
      "    ss_ext_wholesale_cost     decimal(7,2),\n" +
      "    ss_ext_list_price         decimal(7,2),\n" +
      "    ss_ext_tax                decimal(7,2),\n" +
      "    ss_coupon_amt             decimal(7,2),\n" +
      "    ss_net_paid               decimal(7,2),\n" +
      "    ss_net_paid_inc_tax       decimal(7,2),\n" +
      "    ss_net_profit             decimal(7,2)\n" +
      ")\n" +
      " partitioned by (dt string)\n" +
      "clustered by (ss_store_sk, ss_promo_sk)\n" +
      "INTO 4 BUCKETS stored as orc " + " location '" + tableLoc + "'" +
      "  TBLPROPERTIES ('orc.compress'='NONE', 'transactional'='true')");
    Assert.assertTrue(success);

    success = runDDL(driver, "alter table store_sales add partition(dt='2015')");
    Assert.assertTrue(success);
  }

  @Test
  public void testDynamicPartitioning() throws Exception {
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase("testing5")
      .withTable("store_sales")
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();
    connection.beginTransaction();

    for (int i = 0; i < 10; i++) {
      StringBuilder row = new StringBuilder();
      for (int ints = 0; ints < 11; ints++) {
        row.append(ints).append(',');
      }
      for (int decs = 0; decs < 12; decs++) {
        row.append(i + 0.1).append(',');
      }
      row.append("2018-04-").append(i);
      connection.write(row.toString().getBytes());
    }
    connection.commitTransaction();
    connection.close();

    List<String> partitions = queryTable(driver, "show partitions testing5.store_sales");
    // 1 static partition created during setup + 10 dynamic partitions
    assertEquals(11, partitions.size());
    // ignore the first static partition
    for (int i = 1; i < partitions.size(); i++) {
      assertEquals("dt=2018-04-" + (i - 1), partitions.get(i));
    }

    ArrayList<String> res = queryTable(driver, "select * from testing5.store_sales");
    for (String re : res) {
      System.out.println(re);
      assertEquals(true, re.contains("2018-04-"));
    }
  }

  // stream data into streaming table with N buckets, then copy the data into another bucketed table
  // check if bucketing in both was done in the same way
  @Test
  public void testDPStreamBucketingMatchesRegularBucketing() throws Exception {
    int bucketCount = 100;

    String dbUri = "raw://" + new Path(dbFolder.newFolder().toString()).toUri().toString();
    String tableLoc = "'" + dbUri + Path.SEPARATOR + "streamedtable" + "'";
    String tableLoc2 = "'" + dbUri + Path.SEPARATOR + "finaltable" + "'";
    String tableLoc3 = "'" + dbUri + Path.SEPARATOR + "nobucket" + "'";

    // disabling vectorization as this test yields incorrect results with vectorization
    conf.setBoolVar(HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED, false);
    try (IDriver driver = DriverFactory.newDriver(conf)) {
      runDDL(driver, "create database testBucketing3");
      runDDL(driver, "use testBucketing3");
      runDDL(driver, "create table streamedtable ( key1 string,key2 int,data string ) partitioned by (year " +
        "int) clustered by " + "( " + "key1,key2 ) into "
        + bucketCount + " buckets  stored as orc  location " + tableLoc + " TBLPROPERTIES ('transactional'='true')");
      //  In 'nobucket' table we capture bucketid from streamedtable to workaround a hive bug that prevents joins two identically bucketed tables
      runDDL(driver, "create table nobucket ( bucketid int, key1 string,key2 int,data string ) partitioned by " +
        "(year int) location " + tableLoc3);
      runDDL(driver, "create table finaltable ( bucketid int, key1 string,key2 int,data string ) partitioned " +
        "by (year int) clustered by ( key1,key2 ) into "
        + bucketCount + " buckets  stored as orc location " + tableLoc2 + " TBLPROPERTIES ('transactional'='true')");

      String[] records = new String[]{
        "PSFAHYLZVC,29,EPNMA,2017",
        "PPPRKWAYAU,96,VUTEE,2017",
        "MIAOFERCHI,3,WBDSI,2017",
        "CEGQAZOWVN,0,WCUZL,2017",
        "XWAKMNSVQF,28,YJVHU,2017",
        "XBWTSAJWME,2,KDQFO,2017",
        "FUVLQTAXAY,5,LDSDG,2017",
        "QTQMDJMGJH,6,QBOMA,2018",
        "EFLOTLWJWN,71,GHWPS,2018",
        "PEQNAOJHCM,82,CAAFI,2018",
        "MOEKQLGZCP,41,RUACR,2018",
        "QZXMCOPTID,37,LFLWE,2018",
        "EYALVWICRD,13,JEZLC,2018",
        "VYWLZAYTXX,16,DMVZX,2018",
        "OSALYSQIXR,47,HNZVE,2018",
        "JGKVHKCEGQ,25,KSCJB,2018",
        "WQFMMYDHET,12,DTRWA,2018",
        "AJOVAYZKZQ,15,YBKFO,2018",
        "YAQONWCUAU,31,QJNHZ,2018",
        "DJBXUEUOEB,35,IYCBL,2018"
      };

      StrictDelimitedInputWriter wr = StrictDelimitedInputWriter.newBuilder()
        .withFieldDelimiter(',')
        .build();

      HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
        .withDatabase("testBucketing3")
        .withTable("streamedtable")
        .withAgentInfo("UT_" + Thread.currentThread().getName())
        .withRecordWriter(wr)
        .withHiveConf(conf)
        .connect();

      connection.beginTransaction();

      for (String record : records) {
        connection.write(record.getBytes());
      }

      connection.commitTransaction();
      connection.close();

      ArrayList<String> res1 = queryTable(driver, "select row__id.bucketid, * from streamedtable order by key2");
      for (String re : res1) {
        System.out.println(re);
        assertTrue(re.endsWith("2017") || re.endsWith("2018"));
      }

      driver.run("insert into nobucket partition(year) select row__id.bucketid,* from streamedtable");
      ArrayList<String> res = queryTable(driver, "select * from nobucket");
      assertEquals(records.length, res.size());
      runDDL(driver, " insert into finaltable partition(year) select * from nobucket");
      res = queryTable(driver, "select * from finaltable");
      assertEquals(records.length, res.size());
      ArrayList<String> res2 = queryTable(driver,
        "select row__id.bucketid,* from finaltable where row__id.bucketid<>bucketid");
      for (String s : res2) {
        LOG.error(s);
      }
      Assert.assertTrue(res2.isEmpty());

      res2 = queryTable(driver, "select * from finaltable where year=2018");
      assertEquals(13, res2.size());
      for (String s : res2) {
        assertTrue(s.endsWith("2018"));
      }

      res2 = queryTable(driver, "show partitions finaltable");
      assertEquals(2, res2.size());
      assertEquals("year=2017", res2.get(0));
      assertEquals("year=2018", res2.get(1));
    } finally {
      conf.unset(HiveConf.ConfVars.HIVE_VECTORIZATION_ENABLED.varname);
    }
  }

  @Test
  public void testDPTwoLevel() throws Exception {
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();
    connection.beginTransaction();
    connection.write("1,foo,Asia,India".getBytes());
    connection.write("2,bar,Europe,Germany".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("3,foo,Asia,India".getBytes());
    connection.write("4,bar,Europe,Germany".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("5,foo,Asia,China".getBytes());
    connection.write("6,bar,Europe,France".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("7,foo,Asia,China".getBytes());
    connection.write("8,bar,Europe,France".getBytes());
    connection.commitTransaction();
    connection.close();

    List<String> res = queryTable(driver, "select * from " + (dbName + "." + tblName) + " order by id");
    assertEquals(8, res.size());
    assertEquals("1\tfoo\tAsia\tIndia", res.get(0));
    assertEquals("2\tbar\tEurope\tGermany", res.get(1));
    assertEquals("3\tfoo\tAsia\tIndia", res.get(2));
    assertEquals("4\tbar\tEurope\tGermany", res.get(3));
    assertEquals("5\tfoo\tAsia\tChina", res.get(4));
    assertEquals("6\tbar\tEurope\tFrance", res.get(5));
    assertEquals("7\tfoo\tAsia\tChina", res.get(6));
    assertEquals("8\tbar\tEurope\tFrance", res.get(7));

    res = queryTable(driver, "show partitions " + (dbName + "." + tblName));
    assertEquals(4, res.size());
    assertTrue(res.contains("continent=Asia/country=India"));
    assertTrue(res.contains("continent=Asia/country=China"));
    assertTrue(res.contains("continent=Europe/country=Germany"));
    assertTrue(res.contains("continent=Europe/country=France"));
  }

  @Test
  public void testDPTwoLevelMissingPartitionValues() throws Exception {
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();
    connection.beginTransaction();
    connection.write("1,foo,Asia,India".getBytes());
    connection.write("2,bar,Europe,Germany".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("3,foo,Asia,India".getBytes());
    connection.write("4,bar,Europe,Germany".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("5,foo,Asia,China".getBytes());
    connection.write("6,bar,Europe,France".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("7,foo,Asia,China".getBytes());
    connection.write("8,bar,Europe,France".getBytes());
    connection.commitTransaction();
    connection.close();

    List<String> res = queryTable(driver, "select * from " + (dbName + "." + tblName) + " order by id");
    assertEquals(8, res.size());
    assertEquals("1\tfoo\tAsia\tIndia", res.get(0));
    assertEquals("2\tbar\tEurope\tGermany", res.get(1));
    assertEquals("3\tfoo\tAsia\tIndia", res.get(2));
    assertEquals("4\tbar\tEurope\tGermany", res.get(3));
    assertEquals("5\tfoo\tAsia\tChina", res.get(4));
    assertEquals("6\tbar\tEurope\tFrance", res.get(5));
    assertEquals("7\tfoo\tAsia\tChina", res.get(6));
    assertEquals("8\tbar\tEurope\tFrance", res.get(7));

    res = queryTable(driver, "show partitions " + (dbName + "." + tblName));
    assertEquals(4, res.size());
    assertTrue(res.contains("continent=Asia/country=India"));
    assertTrue(res.contains("continent=Asia/country=China"));
    assertTrue(res.contains("continent=Europe/country=Germany"));
    assertTrue(res.contains("continent=Europe/country=France"));
  }

  @Test
  public void testDPTwoLevelNonStringPartitionColumns() throws Exception {
    String tblName = "alerts2";
    String[] partNames = new String[] {"year", "month"};
    createDbAndTable(driver, dbName, tblName, null, fieldNames, colTypes, bucketCols, partNames, loc1, 2,
      "partitioned by (year int, month int)");
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();
    connection.beginTransaction();
    connection.write("1,foo,2018,2".getBytes());
    connection.write("2,bar,2019".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("3,foo,2018".getBytes());
    connection.write("4,bar,2019".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("5,foo,2018".getBytes());
    connection.write("6,bar,2019".getBytes());
    connection.commitTransaction();
    connection.beginTransaction();
    connection.write("7,foo,,".getBytes());
    connection.write("8,bar,,12".getBytes());
    connection.commitTransaction();
    connection.close();

    // when partition column type is not string, the values from __HIVE_DEFAULT_PARTITION__ will be NULL
    String defaultPartitionName = "NULL";
    List<String> res = queryTable(driver, "select * from " + (dbName + "." + tblName) + " order by id");
    assertEquals(8, res.size());
    assertEquals("1\tfoo\t2018\t2", res.get(0));
    assertEquals("2\tbar\t2019\t" + defaultPartitionName, res.get(1));
    assertEquals("3\tfoo\t2018\t" + defaultPartitionName, res.get(2));
    assertEquals("4\tbar\t2019\t" + defaultPartitionName, res.get(3));
    assertEquals("5\tfoo\t2018\t" + defaultPartitionName, res.get(4));
    assertEquals("6\tbar\t2019\t" + defaultPartitionName, res.get(5));
    assertEquals("7\tfoo\t" + defaultPartitionName + "\t" + defaultPartitionName, res.get(6));
    assertEquals("8\tbar\t" + defaultPartitionName + "\t12", res.get(7));

    defaultPartitionName = conf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME);
    res = queryTable(driver, "show partitions " + (dbName + "." + tblName));
    assertEquals(5, res.size());
    assertTrue(res.contains("year=2018/month=2"));
    assertTrue(res.contains("year=2018/month=" + defaultPartitionName));
    assertTrue(res.contains("year=2019/month=" + defaultPartitionName));
    assertTrue(res.contains("year=" + defaultPartitionName + "/month=" + defaultPartitionName));
    assertTrue(res.contains("year=" + defaultPartitionName + "/month=12"));
  }

  @Test
  public void testWriteBeforeBegin() throws Exception {
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();

    // begin + write + commit
    connection.beginTransaction();
    connection.write("1,foo,Asia".getBytes());
    connection.write("2,bar,Europe".getBytes());
    connection.commitTransaction();

    // no begin + write
    Exception exception = null;
    try {
      connection.write("3,SHOULD FAIL!".getBytes());
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().equals("Transaction state is not OPEN. Missing beginTransaction?"));

    // no begin + commit
    exception = null;
    try {
      connection.commitTransaction();
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().equals("Transaction state is not OPEN. Missing beginTransaction?"));

    // no begin + abort
    exception = null;
    try {
      connection.abortTransaction();
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().equals("Transaction state is not OPEN. Missing beginTransaction?"));

    connection.close();
    String defaultPartitionName = conf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME);
    List<String> res = queryTable(driver, "select * from " + (dbName + "." + tblName) + " order by id");
    assertEquals(2, res.size());
    assertEquals("1\tfoo\tAsia\t" + defaultPartitionName, res.get(0));
    assertEquals("2\tbar\tEurope\t" + defaultPartitionName, res.get(1));
  }

  @Test
  public void testRegexInputStreamDP() throws Exception {
    String regex = "([^,]*),(.*),(.*),(.*)";
    StrictRegexWriter writer = StrictRegexWriter.newBuilder()
      // if unspecified, default one or [\r\n] will be used for line break
      .withRegex(regex)
      .build();
    StreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withHiveConf(conf)
      .withRecordWriter(writer)
      .connect();

    String rows = "1,foo,Asia,India\r2,bar,Europe,Germany\r3,baz,Asia,China\r4,cat,Australia,";
    ByteArrayInputStream bais = new ByteArrayInputStream(rows.getBytes());
    connection.beginTransaction();
    connection.write(bais);
    connection.commitTransaction();
    bais.close();
    connection.close();

    List<String> rs = queryTable(driver, "select * from " + dbName + "." + tblName + " order by id");
    Assert.assertEquals(4, rs.size());
    Assert.assertEquals("1\tfoo\tAsia\tIndia", rs.get(0));
    Assert.assertEquals("2\tbar\tEurope\tGermany", rs.get(1));
    Assert.assertEquals("3\tbaz\tAsia\tChina", rs.get(2));
    Assert.assertEquals("4\tcat\tAustralia\t__HIVE_DEFAULT_PARTITION__", rs.get(3));
    rs = queryTable(driver, "show partitions " + dbName + "." + tblName);
    Assert.assertEquals(4, rs.size());
    Assert.assertTrue(rs.contains("continent=Asia/country=India"));
    Assert.assertTrue(rs.contains("continent=Asia/country=China"));
    Assert.assertTrue(rs.contains("continent=Europe/country=Germany"));
    Assert.assertTrue(rs.contains("continent=Australia/country=__HIVE_DEFAULT_PARTITION__"));
  }

  @Test
  public void testJsonInputStreamDP() throws Exception {
    StrictJsonWriter writer = StrictJsonWriter.newBuilder()
      .withLineDelimiterPattern("\\|")
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();

    // 1st Txn
    connection.beginTransaction();
    Assert.assertEquals(HiveStreamingConnection.TxnState.OPEN, connection.getCurrentTransactionState());
    String records = "{\"id\" : 1, \"msg\": \"Hello streaming\", \"continent\": \"Asia\", \"Country\": \"India\"}|" +
      "{\"id\" : 2, \"msg\": \"Hello world\", \"continent\": \"Europe\", \"Country\": \"Germany\"}|" +
      "{\"id\" : 3, \"msg\": \"Hello world!!\", \"continent\": \"Asia\", \"Country\": \"China\"}|" +
      "{\"id\" : 4, \"msg\": \"Hmm..\", \"continent\": \"Australia\", \"Unknown-field\": \"whatever\"}|";
    ByteArrayInputStream bais = new ByteArrayInputStream(records.getBytes());
    connection.write(bais);
    connection.commitTransaction();
    bais.close();
    connection.close();
    List<String> rs = queryTable(driver, "select * from " + dbName + "." + tblName + " order by id");
    Assert.assertEquals(4, rs.size());
    Assert.assertEquals("1\tHello streaming\tAsia\tIndia", rs.get(0));
    Assert.assertEquals("2\tHello world\tEurope\tGermany", rs.get(1));
    Assert.assertEquals("3\tHello world!!\tAsia\tChina", rs.get(2));
    Assert.assertEquals("4\tHmm..\tAustralia\t__HIVE_DEFAULT_PARTITION__", rs.get(3));
    rs = queryTable(driver, "show partitions " + dbName + "." + tblName);
    Assert.assertEquals(4, rs.size());
    Assert.assertTrue(rs.contains("continent=Asia/country=India"));
    Assert.assertTrue(rs.contains("continent=Asia/country=China"));
    Assert.assertTrue(rs.contains("continent=Europe/country=Germany"));
    Assert.assertTrue(rs.contains("continent=Australia/country=__HIVE_DEFAULT_PARTITION__"));
  }

  @Test
  public void testWriteAfterClose() throws Exception {
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();

    // begin + write + commit
    connection.beginTransaction();
    connection.write("1,foo,Asia".getBytes());
    connection.write("2,bar,Europe".getBytes());
    connection.commitTransaction();

    // close + write
    connection.close();

    Exception exception = null;
    try {
      connection.write("3,SHOULD FAIL!".getBytes());
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().endsWith("Streaming connection is closed already."));

    // close + commit
    exception = null;
    try {
      connection.commitTransaction();
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().endsWith("Streaming connection is closed already."));

    // close + abort
    exception = null;
    try {
      connection.abortTransaction();
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().endsWith("Streaming connection is closed already."));

    String defaultPartitionName = conf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME);
    List<String> res = queryTable(driver, "select * from " + (dbName + "." + tblName) + " order by id");
    assertEquals(2, res.size());
    assertEquals("1\tfoo\tAsia\t" + defaultPartitionName, res.get(0));
    assertEquals("2\tbar\tEurope\t" + defaultPartitionName, res.get(1));
  }

  @Test
  public void testWriteAfterAbort() throws Exception {
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName)
      .withTable(tblName)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();

    // begin + write + commit
    connection.beginTransaction();
    connection.write("1,foo,Asia".getBytes());
    connection.write("2,bar,Europe".getBytes());
    connection.commitTransaction();

    // begin + write + abort
    connection.beginTransaction();
    connection.write("3,oops!".getBytes());
    connection.abortTransaction();

    // begin + write + abort
    connection.beginTransaction();
    connection.write("4,I did it again!".getBytes());
    connection.abortTransaction();

    // begin + write + commit
    connection.beginTransaction();
    connection.write("5,Not now!,Europe".getBytes());
    connection.commitTransaction();

    // close + write
    connection.close();
    Exception exception = null;
    try {
      connection.write("6,SHOULD FAIL!".getBytes());
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertTrue(exception.getMessage().equals("Streaming connection is closed already."));
    String defaultPartitionName = conf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME);
    List<String> res = queryTable(driver, "select * from " + (dbName + "." + tblName) + " order by id");
    assertEquals(3, res.size());
    assertEquals("1\tfoo\tAsia\t" + defaultPartitionName, res.get(0));
    assertEquals("2\tbar\tEurope\t" + defaultPartitionName, res.get(1));
    assertEquals("5\tNot now!\tEurope\t" + defaultPartitionName, res.get(2));
  }

  @Test
  public void testTableValidation() throws Exception {
    int bucketCount = 100;

    String dbUri = "raw://" + new Path(dbFolder.newFolder().toString()).toUri().toString();
    String tbl1 = "validation1";
    String tbl2 = "validation2";

    String tableLoc = "'" + dbUri + Path.SEPARATOR + tbl1 + "'";
    String tableLoc2 = "'" + dbUri + Path.SEPARATOR + tbl2 + "'";

    runDDL(driver, "create database testBucketing3");
    runDDL(driver, "use testBucketing3");

    runDDL(driver, "create table " + tbl1 + " ( key1 string, data string ) clustered by ( key1 ) into "
      + bucketCount + " buckets  stored as orc  location " + tableLoc + " TBLPROPERTIES ('transactional'='false')");

    runDDL(driver, "create table " + tbl2 + " ( key1 string, data string ) clustered by ( key1 ) into "
      + bucketCount + " buckets  stored as orc  location " + tableLoc2 + " TBLPROPERTIES ('transactional'='false')");

    StrictDelimitedInputWriter wr = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = null;
    try {
      connection = HiveStreamingConnection.newBuilder()
        .withDatabase("testBucketing3")
        .withTable("validation2")
        .withAgentInfo("UT_" + Thread.currentThread().getName())
        .withRecordWriter(wr)
        .withHiveConf(conf)
        .connect();
      Assert.assertTrue("InvalidTable exception was not thrown", false);
    } catch (InvalidTable e) {
      // expecting this exception
    } finally {
      if (connection != null) {
        connection.close();
      }
    }
    try {
      connection = HiveStreamingConnection.newBuilder()
        .withDatabase("testBucketing3")
        .withTable("validation2")
        .withAgentInfo("UT_" + Thread.currentThread().getName())
        .withRecordWriter(wr)
        .withHiveConf(conf)
        .connect();
      Assert.assertTrue("InvalidTable exception was not thrown", false);
    } catch (InvalidTable e) {
      // expecting this exception
    } finally {
      if (connection != null) {
        connection.close();
      }
    }
  }

  private static boolean runDDL(IDriver driver, String sql) {
    LOG.debug(sql);
    System.out.println(sql);
    try {
      driver.run(sql);
      return true;
    } catch (CommandProcessorException e) {
      LOG.error("Statement: " + sql + " failed: " + e);
      return false;
    }
  }

  private static ArrayList<String> queryTable(IDriver driver, String query) throws IOException {
    try {
      driver.run(query);
    } catch (CommandProcessorException e) {
      throw new RuntimeException(query + " failed: " + e);
    }
    ArrayList<String> res = new ArrayList<String>();
    driver.getResults(res);
    return res;
  }

  // delete db and all tables in it
  public static void dropDB(IMetaStoreClient client, String databaseName) {
    try {
      for (String table : client.listTableNamesByFilter(databaseName, "", (short) -1)) {
        client.dropTable(databaseName, table, true, true);
      }
      client.dropDatabase(databaseName);
    } catch (TException e) {
    }

  }

  ///////// -------- UTILS ------- /////////
  // returns Path of the partition created (if any) else Path of table
  private static Path createDbAndTable(IDriver driver, String databaseName,
    String tableName, List<String> partVals,
    String[] colNames, String[] colTypes,
    String[] bucketCols,
    String[] partNames, String dbLocation, int bucketCount)
    throws Exception {

    String dbUri = "raw://" + new Path(dbLocation).toUri().toString();
    String tableLoc = dbUri + Path.SEPARATOR + tableName;

    runDDL(driver, "create database IF NOT EXISTS " + databaseName + " location '" + dbUri + "'");
    runDDL(driver, "use " + databaseName);
    String crtTbl = "create table " + tableName +
      " ( " + getTableColumnsStr(colNames, colTypes) + " )" +
      getPartitionStmtStr(partNames) +
      " clustered by ( " + join(bucketCols, ",") + " )" +
      " into " + bucketCount + " buckets " +
      " stored as orc " +
      " location '" + tableLoc + "'" +
      " TBLPROPERTIES ('transactional'='true') ";
    runDDL(driver, crtTbl);
    if (partNames != null && partNames.length != 0 && partVals != null) {
      return addPartition(driver, tableName, partVals, partNames);
    }
    return new Path(tableLoc);
  }

  private static Path createDbAndTable(IDriver driver, String databaseName,
    String tableName, List<String> partVals,
    String[] colNames, String[] colTypes,
    String[] bucketCols,
    String[] partNames, String dbLocation, int bucketCount, String partLine)
    throws Exception {

    String dbUri = "raw://" + new Path(dbLocation).toUri().toString();
    String tableLoc = dbUri + Path.SEPARATOR + tableName;

    runDDL(driver, "create database IF NOT EXISTS " + databaseName + " location '" + dbUri + "'");
    runDDL(driver, "use " + databaseName);
    String crtTbl = "create table " + tableName +
      " ( " + getTableColumnsStr(colNames, colTypes) + " )" +
      partLine +
      " clustered by ( " + join(bucketCols, ",") + " )" +
      " into " + bucketCount + " buckets " +
      " stored as orc " +
      " location '" + tableLoc + "'" +
      " TBLPROPERTIES ('transactional'='true') ";
    runDDL(driver, crtTbl);
    if (partNames != null && partNames.length != 0 && partVals != null) {
      return addPartition(driver, tableName, partVals, partNames);
    }
    return new Path(tableLoc);
  }

  private static Path addPartition(IDriver driver, String tableName, List<String> partVals, String[] partNames)
    throws Exception {
    String partSpec = getPartsSpec(partNames, partVals);
    String addPart = "alter table " + tableName + " add partition ( " + partSpec + " )";
    runDDL(driver, addPart);
    return getPartitionPath(driver, tableName, partSpec);
  }

  private static Path getPartitionPath(IDriver driver, String tableName, String partSpec) throws Exception {
    ArrayList<String> res = queryTable(driver, "describe extended " + tableName + " PARTITION (" + partSpec + ")");
    String partInfo = res.get(res.size() - 1);
    int start = partInfo.indexOf("location:") + "location:".length();
    int end = partInfo.indexOf(",", start);
    return new Path(partInfo.substring(start, end));
  }

  private static String getTableColumnsStr(String[] colNames, String[] colTypes) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < colNames.length; ++i) {
      sb.append(colNames[i]).append(" ").append(colTypes[i]);
      if (i < colNames.length - 1) {
        sb.append(",");
      }
    }
    return sb.toString();
  }

  // converts partNames into "partName1 string, partName2 string"
  private static String getTablePartsStr(String[] partNames) {
    if (partNames == null || partNames.length == 0) {
      return "";
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < partNames.length; ++i) {
      sb.append(partNames[i]).append(" string");
      if (i < partNames.length - 1) {
        sb.append(",");
      }
    }
    return sb.toString();
  }

  // converts partNames,partVals into "partName1=val1, partName2=val2"
  private static String getPartsSpec(String[] partNames, List<String> partVals) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < partVals.size(); ++i) {
      sb.append(partNames[i]).append(" = '").append(partVals.get(i)).append("'");
      if (i < partVals.size() - 1) {
        sb.append(",");
      }
    }
    return sb.toString();
  }

  private static String join(String[] values, String delimiter) {
    if (values == null) {
      return null;
    }
    StringBuilder strbuf = new StringBuilder();

    boolean first = true;

    for (Object value : values) {
      if (!first) {
        strbuf.append(delimiter);
      } else {
        first = false;
      }
      strbuf.append(value.toString());
    }

    return strbuf.toString();
  }

  private static String getPartitionStmtStr(String[] partNames) {
    if (partNames == null || partNames.length == 0) {
      return "";
    }
    return " partitioned by (" + getTablePartsStr(partNames) + " )";
  }
}


text:
package jcurry.util.function.testdata;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.ObjDoubleConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.ObjLongConsumer;

public final class BiConsumers {

    private BiConsumers() {}

    // consumes two strings, and adds them to the accumulator
    public static <T, U> BiConsumer<T, U> biConsumerAddsToAccumulatorList(List<Object> accumulator) {
        return (t1, t2) -> { accumulator.add(t1); accumulator.add(t2); };
    }

    public static <T> ObjDoubleConsumer<T> objDoubleConsumerAddsToAccumulatorList(List<Object> accumulator) {
        return (t1, t2) -> { accumulator.add(t1); accumulator.add(t2); };
    }

    public static <T> ObjIntConsumer<T> objIntConsumerAddsToAccumulatorList(List<Object> accumulator) {
        return (t1, t2) -> { accumulator.add(t1); accumulator.add(t2); };
    }

    public static <T> ObjLongConsumer<T> objLongConsumerAddsToAccumulatorList(List<Object> accumulator) {
        return (t1, t2) -> { accumulator.add(t1); accumulator.add(t2); };
    }

}

redpajama_set_name: RedPajamaGithub


text:
To learn about Cisco security vulnerability disclosure policies and publications, access the [Cisco Security Vulnerability Policy](https://tools.cisco.com/security/center/resources/security_vulnerability_policy.html). This document also contains instructions for obtaining fixed software and receiving security vulnerability information from Cisco.

All Cisco Security Advisories are published at: https://www.cisco.com/go/psirt

## Reporting a Vulnerability

Individuals or organizations that are experiencing a product security issue are strongly encouraged to contact the Cisco PSIRT. Cisco welcomes reports from independent researchers, industry organizations, vendors, customers, and other sources concerned with product or network security. The minimal data needed for reporting a security issue is a description of the potential vulnerability.

Please contact the Cisco PSIRT using one of the following methods.

### Emergency Support
- Phone	+1 877 228 7302 (toll-free within North America)
- +1 408 525 6532 (International direct-dial)
- Hours	24 hours a day, 7 days a week

## Nonemergency Support
- Email	psirt@cisco.com
- Hours	Support requests that are received via email are typically acknowledged within 48 hours. Ongoing status on reported issues will be determined as needed.

Cisco encourages the encryption of sensitive information that is sent to Cisco in email messages. The Cisco PSIRT supports encrypted messages via PGP/GNU Privacy Guard (GPG). The Cisco PSIRT public key is available at the following link:  https://tools.cisco.com/security/center/resources/security_vulnerability_policy.html#cpsir


text:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.datalakestore.fluent.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/** Data Lake Store account name availability result information. */
@Immutable
public final class NameAvailabilityInformationInner {
    @JsonIgnore private final ClientLogger logger = new ClientLogger(NameAvailabilityInformationInner.class);

    /*
     * The Boolean value of true or false to indicate whether the Data Lake
     * Store account name is available or not.
     */
    @JsonProperty(value = "nameAvailable", access = JsonProperty.Access.WRITE_ONLY)
    private Boolean nameAvailable;

    /*
     * The reason why the Data Lake Store account name is not available, if
     * nameAvailable is false.
     */
    @JsonProperty(value = "reason", access = JsonProperty.Access.WRITE_ONLY)
    private String reason;

    /*
     * The message describing why the Data Lake Store account name is not
     * available, if nameAvailable is false.
     */
    @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY)
    private String message;

    /**
     * Get the nameAvailable property: The Boolean value of true or false to indicate whether the Data Lake Store
     * account name is available or not.
     *
     * @return the nameAvailable value.
     */
    public Boolean nameAvailable() {
        return this.nameAvailable;
    }

    /**
     * Get the reason property: The reason why the Data Lake Store account name is not available, if nameAvailable is
     * false.
     *
     * @return the reason value.
     */
    public String reason() {
        return this.reason;
    }

    /**
     * Get the message property: The message describing why the Data Lake Store account name is not available, if
     * nameAvailable is false.
     *
     * @return the message value.
     */
    public String message() {
        return this.message;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
    }
}


text:
// grunt protractor --suite bookmarks

/*
  flow:
  > go to bookmarks list >
  > go to add new bookmark > click on cancel (return to bookmarks list) >
  > go to add new bookmark > define name, url and description > click on save >
  > check bookmark added at last item list >
  > click on edit on last added bookmark > update name > click on save >
  > check name on last item list >
  > click on edit on last added bookmark > click on delete >
  > check confirm message > cancel >
  > click on delete > click on delete (return to bookmarks list) >
  > check if last item list is different from removed one

*/

describe("e2e: bookmarks on add, edit and delete", function() {
  var page = require('./page.object');

  it("should go to bookmarks list page", function() {
    page.get();

    var newLink = page.on.list.links.new(); // get element

    expect(newLink.isPresent()).toBeTruthy();
  });

  it("should go to bookmarks add page", function() {
    var newLink = page.on.list.links.new(); // get element

    newLink.click();

    var title = page.on.form.title(); // get element

    expect(title.getText()).toContain('New Bookmark');
  });

  it("should return to bookmarks list page", function() {
    var cancelLink = page.on.form.buttons.cancelLink(); // get element

    cancelLink.click();

    var newLink = page.on.list.links.new(); // get element

    expect(newLink.isPresent()).toBeTruthy();
  });

  it("should add new bookmark", function() {
    var newLink = page.on.list.links.new(); // get element

    newLink.click();

    var nameInput = page.on.form.inputs.name(); // get element
    var urlInput = page.on.form.inputs.url(); // get element
    var descriptionInput = page.on.form.inputs.description(); // get element
    var saveButton = page.on.form.buttons.save(); // get element

    var objectName = 'Protractor e2e';

    nameInput.sendKeys(objectName);
    urlInput.sendKeys('https://angular.github.io/protractor/');
    descriptionInput.sendKeys('This is an automated protractor e2e test');

    saveButton.click();

    // assertion
    expect(
      page.on.table
        .lastRowName() // get element
        .getText()
    ).toContain(objectName);
  });

  it("should go to edit bookmark and cancel edition", function() {
    var lastRow = page.on.table.lastRow(); // get element

    // assertion
    expect(
      page.on.table
        .lastRowName(lastRow) // get element
        .getText()
    ).toContain('Protractor e2e');

    // go to edit
    page.on.table
      .lastRowEditLink(lastRow) // get element
      .click();

    // get elements
    var title = page.on.form.title();
    var nameInput = page.on.form.inputs.name();

    // assertions
    expect(title.getText()).toContain('Edit Bookmark');
    expect(nameInput.getAttribute('value')).toBe('Protractor e2e');

    page.on.form.buttons
      .cancelLink() // get element
      .click(); // cancel edition

    // get element
    var newLink = page.on.list.links.new();

    // assertion
    expect(newLink.isPresent()).toBeTruthy();
  });

  it("should edit bookmark", function() {
    var lastRow = page.on.table.lastRow(); // get element

    var objectName = 'Protractor e2e';

    // assertion
    expect(
      page.on.table
        .lastRowName(lastRow) // get element
        .getText()
    ).toContain(objectName);

    // go to edit
    page.on.table
      .lastRowEditLink(lastRow) // get element
      .click();

    // get elements
    var nameInput = page.on.form.inputs.name();
    var saveButton = page.on.form.buttons.save();

    objectName = 'Protractor e2e Edited';

    nameInput.clear();
    nameInput.sendKeys(objectName);
    saveButton.click();

    // assertion
    expect(
      page.on.table
        .lastRowName() // get element
        .getText()
    ).toContain(objectName);
  });

  it("should delete bookmark", function() {
    var lastRow = page.on.table.lastRow(); // get element

    var objectName = 'Protractor e2e Edited';

    // assertion
    expect(
      page.on.table
        .lastRowName(lastRow) // get element
        .getText()
    ).toContain(objectName);

    // go to edit
    page.on.table
      .lastRowEditLink(lastRow) // get element
      .click();

    page.on.form.buttons
      .deleteConfirm() // get element
      .click(); // show delete confirm

    expect(
      page.on.form
        .nameConfirm() // get element
        .getText()
    ).toContain(objectName);

    expect(
      page.on.form.buttons
        .delete() // get element
        .isPresent()
    ).toBeTruthy();

    page.on.form.buttons
      .cancel() // get element
      .click(); // cancel delete

    expect(
      page.on.form.buttons
        .delete() // get element
        .isPresent()
    ).toBeFalsy();

    page.on.form.buttons
      .deleteConfirm() // get element
      .click(); // show delete confirm again

    expect(
      page.on.form
        .nameConfirm() // get element
        .getText()
    ).toContain(objectName);

    page.on.form.buttons
      .delete() // get element
      .click(); // do delete

    // final assertion
    expect(
      page.on.table
        .lastRowName() // get element
        .getText()
    ).not.toContain(objectName);
  });

});


text:
export { default } from '../src/Select';
export * from '../src/Select';


text:
<?php

namespace PaymentSuite\PayUBundle;

/**
 * Class PayuRequestTypes
 */
class PayuRequestTypes
{
    /**
     * @var string
     *
     * PING request
     */
    const TYPE_PING = 'PING';

    /**
     * @var string
     *
     * GET_PAYMENT_METHODS request
     */
    const TYPE_GET_PAYMENT_METHODS = 'GET_PAYMENT_METHODS';

    /**
     * @var string
     *
     * SUBMIT_TRANSACTION request
     */
    const TYPE_SUBMIT_TRANSACTION = 'SUBMIT_TRANSACTION';

    /**
     * @var string
     *
     * TRANSACTION_RESPONSE_DETAIL request
     */
    const TYPE_TRANSACTION_RESPONSE_DETAIL = 'TRANSACTION_RESPONSE_DETAIL';

    /**
     * @var string
     *
     * ORDER_DETAIL request
     */
    const TYPE_ORDER_DETAIL = 'ORDER_DETAIL';

    /**
     * @var string
     *
     * ORDER_DETAIL_BY_REFERENCE_CODE request
     */
    const TYPE_ORDER_DETAIL_BY_REFERENCE_CODE = 'ORDER_DETAIL_BY_REFERENCE_CODE';
}


text:
package com.netflix.appinfo;

/**
 * @author David Liu
 */
final class PropertyBasedAmazonInfoConfigConstants {

    static final String LOG_METADATA_ERROR_KEY = "logAmazonMetadataErrors";
    static final String READ_TIMEOUT_KEY = "mt.read_timeout";
    static final String CONNECT_TIMEOUT_KEY = "mt.connect_timeout";
    static final String NUM_RETRIES_KEY = "mt.num_retries";
    static final String FAIL_FAST_ON_FIRST_LOAD_KEY = "mt.fail_fast_on_first_load";

    static final String SHOULD_VALIDATE_INSTANCE_ID_KEY = "validateInstanceId";

    static class Values {
        static final int DEFAULT_READ_TIMEOUT = 5000;
        static final int DEFAULT_CONNECT_TIMEOUT = 2000;
        static final int DEFAULT_NUM_RETRIES = 3;
    }
}


text:
var TICKS_IN_MILLISECONDS = 10000,
    MILLISECONDS_IN_HOUR = 60 * 60 * 1000,
    NET_START_DATE = new Date("0001-01-01").getTime(),
    MAX_TICKS = 3155378975999999999,
    MIN_TICKS = 0;

exports.netTicksToDate = function (ticks, timezoneOffsetHours) {
    var netMilliseconds, timezoneOffsetMilliseconds;

    if (!ticks || typeof ticks !== 'number' || ticks < MIN_TICKS || ticks > MAX_TICKS) {
        throw 'ticks should be a number between ' + MIN_TICKS + ' and ' + MAX_TICKS;
    }

    if (timezoneOffsetHours) {
        if (typeof timezoneOffsetHours !== 'number' || timezoneOffsetHours < -12 || timezoneOffsetHours > 14) {
            throw 'timezoneOffsetHours is optional number between -12 and 14';
        }
    }

    netMilliseconds = Math.floor(ticks / TICKS_IN_MILLISECONDS);
    timezoneOffsetMilliseconds = (timezoneOffsetHours || 0) * MILLISECONDS_IN_HOUR;

    return new Date(netMilliseconds + NET_START_DATE - timezoneOffsetMilliseconds);
};


text:
package dao

import (
	"context"
	"fmt"

	"go-common/app/interface/openplatform/monitor-end/model"
	"go-common/library/cache/redis"
	"go-common/library/log"
)

func mailGroupKey(name string, t *model.Target, code string) string {
	return fmt.Sprintf("%s:%s", name, targetKey(t, code))
}

func targetKey(t *model.Target, code string) string {
	return fmt.Sprintf("%s_%s_%s_%s_%s", t.Source, t.Product, t.Event, t.SubEvent, code)
}

func (d *Dao) pingRedis(c context.Context) (err error) {
	conn := d.redis.Get(c)
	if _, err = conn.Do("SET", "PING", "PONG"); err != nil {
		log.Error("remote redis: conn.Do(SET,PING,PONG) error(%+v)", err)
	}
	conn.Close()
	return
}

// GetMailLock .
func (d *Dao) GetMailLock(c context.Context, name string, interval int, t *model.Target, code string) (ok bool, err error) {
	if name == "" || interval == 0 {
		return
	}
	conn := d.redis.Get(c)
	defer conn.Close()
	key := mailGroupKey(name, t, code)
	if ok, err = redis.Bool(conn.Do("SETNX", key, "1")); err != nil {
		if err == redis.ErrNil {
			err = nil
		} else {
			log.Error("d.redis.conn.Do(SETNX(%s)) error(%v)", key, err)
			return
		}
	}
	if ok {
		conn.Do("EXPIRE", key, interval)
	}
	return
}

// TargetIncr get current target error amount.
func (d *Dao) TargetIncr(c context.Context, t *model.Target, code string) (res int) {
	var (
		conn = d.redis.Get(c)
		err  error
		key  = targetKey(t, code)
	)
	defer conn.Close()
	if res, err = redis.Int(conn.Do("INCR", key)); err != nil {
		log.Error("d.redis.intr error(%+v)", err)
		return
	}
	if res == 1 {
		conn.Do("EXPIRE", key, t.Duration)
	}
	return
}


text:
const template = /** @type {!HTMLTemplateElement} */(document.createElement('template'));
template.innerHTML = `

<fairness-privacy-container hidden$="[[!omittedSlices_.length]]"
                            omitted-slices="[[omittedSlices_]]">
</fairness-privacy-container>

  <paper-dropdown-menu label="Baseline">
    <paper-listbox selected="{{baseline_}}" attr-for-selected="slice"
                   class="dropdown-content" slot="dropdown-content">
      <template is="dom-repeat" items="[[slices_]]">
        <paper-item slice="[[item]]">
          [[item]]
        </paper-item>
      </template>
    </paper-listbox>
  </paper-dropdown-menu>

    <paper-dialog id="dialog">

Baseline

        Select a slice from the "Baseline" dropdown. Slices are the subsets of data for which metrics are evaluated. The baseline is the slice which all other slices are compared to. By default, baseline is "Overall", meaning the entire dataset.

        <paper-button dialog-confirm autofocus>Close</paper-button>

    </paper-dialog>
    <paper-icon-button icon="info-outline" id="Information" on-click="openInfoDialog_">

<template is="dom-repeat" items="[[metrics]]">

  <template is="dom-if" if="[[item]]">
    <fairness-metric-summary data="[[data]]" eval-name="[[evalName]]"
                             metric="[[item]]" slices="[[slices_]]" baseline="[[baseline_]]"
                             data-compare="[[dataCompare]]" eval-name-compare="[[evalNameCompare]]">
    </fairness-metric-summary>
  </template>
</template>
`;
export {template};


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

// for controller; don't forget to include Microsoft.Xna.Framework in References
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace RockCounterUC
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class RockCounter : UserControl
    {
        string[] rocks = new string[] { "0", "0,", "0", "0", "0", "0" };

        public enum DPadDirection
        {
            Up,
            Down,
            Left,
            Right
        }

        // initialize rock count values to 0
        int red = 0, orange = 0, yellow = 0, green = 0, blue = 0, purple = 0;

        // ring buffer for rocks, main camera index, sub camera index
        int rockRing = 0;

        bool rocks_restored;

        public RockCounter()
        {
            InitializeComponent();
        }

        // dpad up functions
        public void DPadButton(DPadDirection dir, bool state)
        {
            // if up is pressed
            if (state)
            {
                switch(dir)
                {
                    case DPadDirection.Up:
                    case DPadDirection.Down:
                        {
                            // call the function
                            rockIncrement((dir == DPadDirection.Up ? 1 : -1));
                        }
                        break;
                    case DPadDirection.Left:
                    case DPadDirection.Right:
                        {
                            rockRing += (dir == DPadDirection.Right ? 1 : -1);

                            rockRing = rockRing % 6;
                            if (rockRing < 0)
                                rockRing = 5;

                            ringSwitch();
                        }
                        break;
                }
            }
        }

        private void Rock_Restorer_Click(object sender, RoutedEventArgs e)
        {
            string[] rocks;
            rocks = rock_file_reader();
            string rock;
            for (int i = 0; i < 6; i++)
            {
                rock = rocks[i];
                int aux = int.Parse(rock);
                if (i == 0) { red = aux; RedCount.Text = red.ToString(); RedCountShadow.Text = red.ToString(); }
                if (i == 1) { orange = aux; OrangeCount.Text = orange.ToString(); OrangeCountShadow.Text = orange.ToString(); }
                if (i == 2) { yellow = aux; YellowCount.Text = yellow.ToString(); YellowCountShadow.Text = yellow.ToString(); }
                if (i == 3) { green = aux; GreenCount.Text = green.ToString(); GreenCountShadow.Text = green.ToString(); }
                if (i == 4) { blue = aux; BlueCount.Text = blue.ToString(); BlueCountShadow.Text = blue.ToString(); }
                if (i == 5) { purple = aux; PurpleCount.Text = purple.ToString(); PurpleCountShadow.Text = purple.ToString(); }
            }
            Rock_Restorer.IsEnabled = false;
            Rock_Restorer.Visibility = Visibility.Hidden;
            rocks_restored = true;
        }
        private string[] rock_file_reader()
        {
            string[] rocks = new string[] { "0", "0", "0", "0", "0", "0" };
            if (File.Exists(@"rocks.txt"))
            {
                StreamReader rreader = new StreamReader(@"rocks.txt");
                rocks = rreader.ReadToEnd().Split(',');
                rreader.Close();
            }
            return rocks;
        }
        private void rock_file_writer(string[] rocks)
        {
            StreamWriter rwriter = new StreamWriter(@"rocks.txt");
            foreach (string rock in rocks)
            {
                rwriter.Write(rock + ",");
            }
            rwriter.Close();
        }

        //
        //
        //  I WANT SO BADLY to do this with a 5-liner... but it's probably better if I let SOME of this be recognizable.
        //            -Eric
        void ringSwitch()
        {
            switch (rockRing)
            {
                // bold text block for red rocks and normalizes neighboring text blocks
                case 0:
                    PurpleTextBlock.FontWeight = FontWeights.Normal;
                    RedTextBlock.FontWeight = FontWeights.UltraBold;
                    OrangeTextBlock.FontWeight = FontWeights.Normal;

                    PurpleRock.Stroke = Brushes.Black;
                    RedRock.Stroke = Brushes.White;
                    OrangeRock.Stroke = Brushes.Black;

                    PurpleRock.StrokeThickness = 1;
                    RedRock.StrokeThickness = 4;
                    OrangeRock.StrokeThickness = 1;
                    return;
                // bold text block for orange rocks and normalizes neighboring text blocks
                case 1:
                    RedTextBlock.FontWeight = FontWeights.Normal;
                    OrangeTextBlock.FontWeight = FontWeights.UltraBold;
                    YellowTextBlock.FontWeight = FontWeights.Normal;

                    RedRock.Stroke = Brushes.Black;
                    OrangeRock.Stroke = Brushes.White;
                    YellowRock.Stroke = Brushes.Black;

                    RedRock.StrokeThickness = 1;
                    OrangeRock.StrokeThickness = 4;
                    YellowRock.StrokeThickness = 1;
                    return;
                // bold text block for yellow rocks and normalizes neighboring text blocks
                case 2:
                    OrangeTextBlock.FontWeight = FontWeights.Normal;
                    YellowTextBlock.FontWeight = FontWeights.UltraBold;
                    GreenTextBlock.FontWeight = FontWeights.Normal;

                    OrangeRock.Stroke = Brushes.Black;
                    YellowRock.Stroke = Brushes.White;
                    GreenRock.Stroke = Brushes.Black;

                    OrangeRock.StrokeThickness = 1;
                    YellowRock.StrokeThickness = 4;
                    GreenRock.StrokeThickness = 1;
                    return;
                // bold text block for green rocks and normalizes neighboring text blocks
                case 3:
                    YellowTextBlock.FontWeight = FontWeights.Normal;
                    GreenTextBlock.FontWeight = FontWeights.UltraBold;
                    BlueTextBlock.FontWeight = FontWeights.Normal;

                    YellowRock.Stroke = Brushes.Black;
                    GreenRock.Stroke = Brushes.White;
                    BlueRock.Stroke = Brushes.Black;

                    YellowRock.StrokeThickness = 1;
                    GreenRock.StrokeThickness = 4;
                    BlueRock.StrokeThickness = 1;
                    return;
                // bold text block for blue rocks and normalizes neighboring text blocks
                case 4:
                    GreenTextBlock.FontWeight = FontWeights.Normal;
                    BlueTextBlock.FontWeight = FontWeights.UltraBold;
                    PurpleTextBlock.FontWeight = FontWeights.Normal;

                    GreenRock.Stroke = Brushes.Black;
                    BlueRock.Stroke = Brushes.White;
                    PurpleRock.Stroke = Brushes.Black;

                    GreenRock.StrokeThickness = 1;
                    BlueRock.StrokeThickness = 4;
                    PurpleRock.StrokeThickness = 1;
                    return;
                // bold text block for purple rocks and normalizes neighboring text blocks
                case 5:
                    BlueTextBlock.FontWeight = FontWeights.Normal;
                    PurpleTextBlock.FontWeight = FontWeights.UltraBold;
                    RedTextBlock.FontWeight = FontWeights.Normal;

                    BlueRock.Stroke = Brushes.Black;
                    PurpleRock.Stroke = Brushes.White;
                    RedRock.Stroke = Brushes.Black;

                    BlueRock.StrokeThickness = 1;
                    PurpleRock.StrokeThickness = 4;
                    RedRock.StrokeThickness = 1;
                    return;
            }
        }

        // the function that changes rock count
        void rockIncrement(int incrementValue)
        {
            if (!File.Exists(@"rocks.txt") && !rocks_restored) rocks_restored = true;
            if (rocks_restored == false)
            {
                rock_file_writer(rocks);
                rocks_restored = true;
                Rock_Restorer.Visibility = Visibility.Collapsed;
            }
            switch (rockRing)
            {
                // change red count and display it
                case 0:
                    red = red + incrementValue;
                    if (red < 0)
                        red = 0;
                    RedCount.Text = red.ToString();
                    RedCountShadow.Text = red.ToString();
                    rocks[0] = red.ToString();
                    rock_file_writer(rocks);
                    return;
                // change red count and display it
                case 1:
                    orange = orange + incrementValue;
                    if (orange < 0)
                        orange = 0;
                    OrangeCount.Text = orange.ToString();
                    OrangeCountShadow.Text = orange.ToString();
                    rocks[1] = orange.ToString();
                    rock_file_writer(rocks);
                    return;
                // change red count and display it
                case 2:
                    yellow = yellow + incrementValue;
                    if (yellow < 0)
                        yellow = 0;
                    YellowCount.Text = yellow.ToString();
                    YellowCountShadow.Text = yellow.ToString();
                    rocks[2] = yellow.ToString();
                    rock_file_writer(rocks);
                    return;
                // change red count and display it
                case 3:
                    green = green + incrementValue;
                    if (green < 0)
                        green = 0;
                    GreenCount.Text = green.ToString();
                    GreenCountShadow.Text = green.ToString();
                    rocks[3] = green.ToString();
                    rock_file_writer(rocks);
                    return;
                // change red count and display it
                case 4:
                    blue = blue + incrementValue;
                    if (blue < 0)
                        blue = 0;
                    BlueCount.Text = blue.ToString();
                    BlueCountShadow.Text = blue.ToString();
                    rocks[4] = blue.ToString();
                    rock_file_writer(rocks);
                    return;
                // change red count and display it
                case 5:
                    purple = purple + incrementValue;
                    if (purple == -1)
                        purple = 0;
                    PurpleCount.Text = purple.ToString();
                    PurpleCountShadow.Text = purple.ToString();
                    rocks[5] = purple.ToString();
                    rock_file_writer(rocks);
                    return;
            }
        }

        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Grid g = (sender as Grid);
            if (g == null) return; //WOOPSIE
            int index = Grid.GetColumn(g);
            rockRing = index;
            ringSwitch();
            int dif=0;
            if (e.ChangedButton == MouseButton.Left) dif=1;
            else if (e.ChangedButton == MouseButton.Right) dif=-1;
            if (dif != 0)
                rockIncrement(dif);
        }
    }
}


text:
#pragma once
#include <aws/shield/Shield_EXPORTS.h>
#include <aws/core/utils/memory/stl/AWSVector.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <utility>

namespace Aws
{
template<typename RESULT_TYPE>
class AmazonWebServiceResult;

namespace Utils
{
namespace Json
{
  class JsonValue;
} // namespace Json
} // namespace Utils
namespace Shield
{
namespace Model
{
  class AWS_SHIELD_API ListResourcesInProtectionGroupResult
  {
  public:
    ListResourcesInProtectionGroupResult();
    ListResourcesInProtectionGroupResult(const Aws::AmazonWebServiceResult<Aws::Utils::Json::JsonValue>& result);
    ListResourcesInProtectionGroupResult& operator=(const Aws::AmazonWebServiceResult<Aws::Utils::Json::JsonValue>& result);

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline const Aws::Vector<Aws::String>& GetResourceArns() const{ return m_resourceArns; }

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline void SetResourceArns(const Aws::Vector<Aws::String>& value) { m_resourceArns = value; }

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline void SetResourceArns(Aws::Vector<Aws::String>&& value) { m_resourceArns = std::move(value); }

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline ListResourcesInProtectionGroupResult& WithResourceArns(const Aws::Vector<Aws::String>& value) { SetResourceArns(value); return *this;}

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline ListResourcesInProtectionGroupResult& WithResourceArns(Aws::Vector<Aws::String>&& value) { SetResourceArns(std::move(value)); return *this;}

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline ListResourcesInProtectionGroupResult& AddResourceArns(const Aws::String& value) { m_resourceArns.push_back(value); return *this; }

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline ListResourcesInProtectionGroupResult& AddResourceArns(Aws::String&& value) { m_resourceArns.push_back(std::move(value)); return *this; }

    /**
     *
The Amazon Resource Names (ARNs) of the resources that are included in the
     * protection group.

     */
    inline ListResourcesInProtectionGroupResult& AddResourceArns(const char* value) { m_resourceArns.push_back(value); return *this; }

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline const Aws::String& GetNextToken() const{ return m_nextToken; }

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline void SetNextToken(const Aws::String& value) { m_nextToken = value; }

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline void SetNextToken(Aws::String&& value) { m_nextToken = std::move(value); }

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline void SetNextToken(const char* value) { m_nextToken.assign(value); }

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline ListResourcesInProtectionGroupResult& WithNextToken(const Aws::String& value) { SetNextToken(value); return *this;}

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline ListResourcesInProtectionGroupResult& WithNextToken(Aws::String&& value) { SetNextToken(std::move(value)); return *this;}

    /**
     *
If you specify a value for MaxResults and you have more
     * resources in the protection group than the value of MaxResults, AWS Shield
     * Advanced returns this token that you can use in your next request, to get the
     * next batch of objects.

     */
    inline ListResourcesInProtectionGroupResult& WithNextToken(const char* value) { SetNextToken(value); return *this;}

  private:

    Aws::Vector<Aws::String> m_resourceArns;

    Aws::String m_nextToken;
  };

} // namespace Model
} // namespace Shield
} // namespace Aws


text:
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/angular-ui/ui-select?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

AngularJS-native version of [Select2](http://ivaynberg.github.io/select2/) and [Selectize](http://brianreavis.github.io/selectize.js/).

[Getting Started](https://github.com/angular-ui/ui-select/wiki/Getting-Started)  `bower install angular-ui-select`

- [Demo](http://plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview)
- [Demo Multiselect](http://plnkr.co/edit/juqoNOt1z1Gb349XabQ2?p=preview)
- [Examples](https://github.com/angular-ui/ui-select/blob/master/examples)
- [Documentation](https://github.com/angular-ui/ui-select/wiki)

## Last Changes

- Check [CHANGELOG.md](/CHANGELOG.md)

## Features

- Search, Select, and Multi-select
- Themes: Bootstrap, Select2 and Selectize
- Keyboard support
- jQuery not required (except for old browsers)
- Small code base: 4.57KB min/gzipped vs 20KB for select2

For the roadmap, check [issue #3](https://github.com/angular-ui/ui-select/issues/3) and the [Wiki page](https://github.com/angular-ui/ui-select/wiki/Roadmap).

## Installation using [Composer](http://getcomposer.org/)

Make sure composer is install globally before we proceed. After that we need to add below piece of code in `composer.json` file located inside your project root folder.

```
{
    "require": {
        "components/ui-select": "dev-master"
    }
}
```

- Run `composer update` and composer will install the component.
- Inside your HTML add below script and link tags.
  - select.js: `<script src="components/ui-select/dist/select.min.js"></script>`
  - select.css: `<link rel="stylesheet" href="components/ui-select/dist/select.min.css">`

## Development

### Prepare your environment
* Install [Node.js](http://nodejs.org/) and NPM (should come with)
* Install global dev dependencies: `npm install -g bower gulp`
* Install local dev dependencies: `npm install && bower install` in repository directory

### Development Commands

* `gulp` to jshint, build and test
* `gulp build` to jshint and build
* `gulp test` for one-time test with karma (also build and jshint)
* `gulp watch` to watch src files to jshint, build and test when changed

## Contributing

- Check [CONTRIBUTING.md](/CONTRIBUTING.md)
- Run the tests
- Try the [examples](https://github.com/angular-ui/ui-select/blob/master/examples)

When issuing a pull request, please exclude changes from the "dist" folder to avoid merge conflicts.


text:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migrate extends CI_Controller
{
    public function index()
    {
        $this->load->library('migration');

        if ($this->migration->current() === FALSE)
        {
            show_error($this->migration->error_string());
        }
        else
        {
            echo 'Migrations ran successfully!';
        }
    }

}