Exemple #1
0
 public void setUpArrayTables() {
   transportExecutor.exec(
       "create table any_table ("
           + "  id int primary key,"
           + "  temps array(double),"
           + "  names array(string),"
           + "  tags array(string)"
           + ") with (number_of_replicas=0)");
   transportExecutor.ensureGreen();
   SQLResponse response =
       transportExecutor.exec(
           "insert into any_table (id, temps, names, tags) values (?,?,?,?), (?,?,?,?), (?,?,?,?), (?,?,?,?)",
           1,
           Arrays.asList(0L, 0L, 0L),
           Arrays.asList("Dornbirn", "Berlin", "St. Margrethen"),
           Arrays.asList("cool"),
           2,
           Arrays.asList(0, 1, -1),
           Arrays.asList("Dornbirn", "Dornbirn", "Dornbirn"),
           Arrays.asList("cool", null),
           3,
           Arrays.asList(42, -42),
           Arrays.asList("Hangelsberg", "Berlin"),
           Arrays.asList("kuhl", "cool"),
           4,
           null,
           null,
           Arrays.asList("kuhl", null));
   assertThat(response.rowCount(), is(4L));
   transportExecutor.refresh("any_table");
 }
Exemple #2
0
  public void setUpEmployees() {
    transportExecutor.exec(
        "create table employees ("
            + " name string, "
            + " department string,"
            + " hired timestamp, "
            + " age short,"
            + " income double, "
            + " good boolean"
            + ") with (number_of_replicas=0)");
    transportExecutor.ensureGreen();
    transportExecutor.exec(
        "insert into employees (name, department, hired, age, income, good) values (?, ?, ?, ?, ?, ?)",
        new Object[] {"dilbert", "engineering", "1985-01-01", 47, 4000.0, true});
    transportExecutor.exec(
        "insert into employees (name, department, hired, age, income, good) values (?, ?, ?, ?, ?, ?)",
        new Object[] {"wally", "engineering", "2000-01-01", 54, 6000.0, true});
    transportExecutor.exec(
        "insert into employees (name, department, hired, age, income, good) values (?, ?, ?, ?, ?, ?)",
        new Object[] {
          "pointy haired boss", "management", "2010-10-10", 45, Double.MAX_VALUE, false
        });

    transportExecutor.exec(
        "insert into employees (name, department, hired, age, income, good) values (?, ?, ?, ?, ?, ?)",
        new Object[] {"catbert", "HR", "1990-01-01", 12, 999999999.99, false});
    transportExecutor.exec(
        "insert into employees (name, department, income) values (?, ?, ?)",
        new Object[] {"ratbert", "HR", 0.50});
    transportExecutor.exec(
        "insert into employees (name, department, age) values (?, ?, ?)",
        new Object[] {"asok", "internship", 28});
    transportExecutor.refresh("employees");
  }
Exemple #3
0
 public void setUpPartitionedTableWithName() {
   transportExecutor.exec(
       "create table parted (id int, name string, date timestamp) partitioned by (date)");
   transportExecutor.ensureGreen();
   transportExecutor.execBulk(
       "insert into parted (id, name, date) values (?, ?, ?)",
       new Object[][] {
         {1, "Trillian", null},
         {2, null, 0L},
         {3, "Ford", 1396388720242L}
       });
   transportExecutor.ensureGreen();
   transportExecutor.refresh("parted");
 }
Exemple #4
0
 public void setUpCharacters() {
   transportExecutor.exec(
       "create table characters (id int primary key, name string, female boolean, details object)");
   transportExecutor.ensureGreen();
   transportExecutor.execBulk(
       "insert into characters (id, name, female) values (?, ?, ?)",
       new Object[][] {
         new Object[] {1, "Arthur", false},
         new Object[] {2, "Ford", false},
         new Object[] {3, "Trillian", true},
         new Object[] {4, "Arthur", true}
       });
   transportExecutor.refresh("characters");
 }
Exemple #5
0
 public void partitionTableSetup() {
   transportExecutor.exec(
       "create table parted ("
           + "id int primary key,"
           + "date timestamp primary key,"
           + "o object(ignored)"
           + ") partitioned by (date) with (number_of_replicas=0)");
   transportExecutor.ensureGreen();
   transportExecutor.exec("insert into parted (id, date) values (1, '2014-01-01')");
   transportExecutor.exec("insert into parted (id, date) values (2, '2014-01-01')");
   transportExecutor.exec("insert into parted (id, date) values (3, '2014-02-01')");
   transportExecutor.exec("insert into parted (id, date) values (4, '2014-02-01')");
   transportExecutor.exec("insert into parted (id, date) values (5, '2014-02-01')");
   transportExecutor.refresh("parted");
 }
Exemple #6
0
  public void groupBySetup(String numericType) throws Exception {
    transportExecutor.exec(
        String.format(
            "create table characters ("
                + " race string,"
                + " gender string,"
                + " age %s,"
                + " birthdate timestamp,"
                + " name string,"
                + " details object as (job string),"
                + " details_ignored object(ignored)"
                + ")",
            numericType));
    transportExecutor.ensureYellowOrGreen();

    Map<String, String> details = newHashMap();
    details.put("job", "Sandwitch Maker");
    transportExecutor.exec(
        "insert into characters (race, gender, age, birthdate, name, details) values (?, ?, ?, ?, ?, ?)",
        new Object[] {"Human", "male", 34, "1975-10-01", "Arthur Dent", details});

    details = newHashMap();
    details.put("job", "Mathematician");
    transportExecutor.exec(
        "insert into characters (race, gender, age, birthdate, name, details) values (?, ?, ?, ?, ?, ?)",
        new Object[] {"Human", "female", 32, "1978-10-11", "Trillian", details});
    transportExecutor.exec(
        "insert into characters (race, gender, age, birthdate, name, details) values (?, ?, ?, ?, ?, ?)",
        new Object[] {"Human", "female", 43, "1970-01-01", "Anjie", null});
    transportExecutor.exec(
        "insert into characters (race, gender, age, name) values (?, ?, ?, ?)",
        new Object[] {"Human", "male", 112, "Ford Perfect"});

    transportExecutor.exec(
        "insert into characters (race, gender, name) values ('Android', 'male', 'Marving')");
    transportExecutor.exec(
        "insert into characters (race, gender, name) values ('Vogon', 'male', 'Jeltz')");
    transportExecutor.exec(
        "insert into characters (race, gender, name) values ('Vogon', 'male', 'Kwaltz')");
    transportExecutor.refresh("characters");
  }
Exemple #7
0
 public void setUpObjectTable() {
   transportExecutor.exec(
       "create table ot ("
           + "  title string,"
           + "  author object(dynamic) as ("
           + "    name object(strict) as ("
           + "      first_name string,"
           + "      last_name string"
           + "    ),"
           + "    age integer"
           + "  ),"
           + "  details object(ignored) as ("
           + "    num_pages integer"
           + "  )"
           + ") with (number_of_replicas = 0)");
   transportExecutor.exec(
       "insert into ot (title, author, details) values (?, ?, ?)",
       new Object[] {
         "The Hitchhiker's Guide to the Galaxy",
         new HashMap<String, Object>() {
           {
             put(
                 "name",
                 new HashMap<String, Object>() {
                   {
                     put("first_name", "Douglas");
                     put("last_name", "Adams");
                   }
                 });
             put("age", 49);
           }
         },
         new HashMap<String, Object>() {
           {
             put("num_pages", 224);
           }
         }
       });
   transportExecutor.refresh("ot");
 }
Exemple #8
0
 public void setUpObjectMappingWithUnknownTypes() throws Exception {
   transportExecutor
       .prepareCreate("ut")
       .setSettings(
           ImmutableSettings.builder()
               .put("number_of_replicas", 0)
               .put("number_of_shards", 2)
               .build())
       .addMapping(
           Constants.DEFAULT_MAPPING_TYPE,
           new HashMap<String, Object>() {
             {
               put(
                   "properties",
                   new HashMap<String, Object>() {
                     {
                       put(
                           "name",
                           new HashMap<String, Object>() {
                             {
                               put("type", "string");
                               put("store", "false");
                               put("index", "not_analyzed");
                             }
                           });
                       put(
                           "location",
                           new HashMap<String, Object>() {
                             {
                               put("type", "geo_shape");
                             }
                           });
                       put(
                           "o",
                           new HashMap<String, Object>() {
                             {
                               put("type", "object");
                             }
                           });
                       put(
                           "population",
                           new HashMap<String, Object>() {
                             {
                               put("type", "long");
                               put("store", "false");
                               put("index", "not_analyzed");
                             }
                           });
                     }
                   });
             }
           })
       .execute()
       .actionGet();
   transportExecutor
       .client()
       .prepareIndex("ut", Constants.DEFAULT_MAPPING_TYPE, "id1")
       .setSource(
           "{\"name\":\"Berlin\",\"location\":{\"type\": \"point\", \"coordinates\": [52.5081, 13.4416]}, \"population\":3500000}")
       .execute()
       .actionGet();
   transportExecutor
       .client()
       .prepareIndex("ut", Constants.DEFAULT_MAPPING_TYPE, "id2")
       .setSource(
           "{\"name\":\"Dornbirn\",\"location\":{\"type\": \"point\", \"coordinates\": [47.3904,9.7562]}, \"population\":46080}")
       .execute()
       .actionGet();
   transportExecutor.refresh("ut");
 }