/** * Checks for column. * * @param schema * the schema * @param columnName * the column name * @return true, if successful */ public static boolean hasColumn(Schema schema, String columnName) { try { schema.getColumn(columnName); return true; } catch (IllegalArgumentException e) { return false; } }
public KuduRow(Object object, Schema schema) { super(validFields(object)); for (Class<?> c = object.getClass(); c != null; c = c.getSuperclass()) { basicValidation(c.getDeclaredFields()) .filter(field -> schema.getColumn(field.getName()) != null) .forEach(cField -> { try { cField.setAccessible(true); setField(schema.getColumnIndex(cField.getName()), cField.getName(), cField.get(object)); } catch (IllegalAccessException e) { String error = String.format("Cannot get value for %s", cField.getName()); throw new IllegalArgumentException(error, e); } }); } }
/** * Test creating and deleting a table through a KuduClient. */ @Test(timeout = 100000) public void testCreateDeleteTable() throws Exception { // Check that we can create a table. client.createTable(TABLE_NAME, basicSchema, getBasicCreateTableOptions()); assertFalse(client.getTablesList().getTablesList().isEmpty()); assertTrue(client.getTablesList().getTablesList().contains(TABLE_NAME)); // Check that we can delete it. client.deleteTable(TABLE_NAME); assertFalse(client.getTablesList().getTablesList().contains(TABLE_NAME)); // Check that we can re-recreate it, with a different schema. List<ColumnSchema> columns = new ArrayList<>(basicSchema.getColumns()); columns.add(new ColumnSchema.ColumnSchemaBuilder("one more", Type.STRING).build()); Schema newSchema = new Schema(columns); client.createTable(TABLE_NAME, newSchema, getBasicCreateTableOptions()); // Check that we can open a table and see that it has the new schema. KuduTable table = client.openTable(TABLE_NAME); assertEquals(newSchema.getColumnCount(), table.getSchema().getColumnCount()); assertTrue(table.getPartitionSchema().isSimpleRangePartitioning()); // Check that the block size parameter we specified in the schema is respected. assertEquals(4096, newSchema.getColumn("column3_s").getDesiredBlockSize()); assertEquals(ColumnSchema.Encoding.DICT_ENCODING, newSchema.getColumn("column3_s").getEncoding()); assertEquals(ColumnSchema.CompressionAlgorithm.LZ4, newSchema.getColumn("column3_s").getCompressionAlgorithm()); }
if (!schema.getColumn(columnInfo.getColumnName()).getType() .equals(KuduDBValidationClassMapper.getValidTypeForClass(columnInfo.getType())))
/** * Set the specified column to null * @param columnName Name of the column * @throws IllegalArgumentException if the column doesn't exist or cannot be set to null * @throws IllegalStateException if the row was already applied */ public void setNull(String columnName) { setNull(this.schema.getColumn(columnName)); }
public KuduPredicate toPredicate(Schema schema) { return toPredicate(schema.getColumn(this.column)); } public KuduPredicate toPredicate(ColumnSchema column) {
/** * Get the type of a column in this result. * @param columnName name of the column * @return a type */ public Type getColumnType(String columnName) { return this.schema.getColumn(columnName).getType(); }
private KuduScanner scannerForFilters(Iterable<Row> filters, KuduTable table) throws KuduException { List<Row> filtersList = Lists.newArrayList(filters); if (filtersList.size() == 0) { throw new RuntimeException("Kudu existing filter was not provided."); } if (filtersList.get(0).schema() == null) { throw new RuntimeException("Kudu existing filter did not contain a schema."); } if (hasAccumulators()) { accumulators.getLongAccumulators().get(ACCUMULATOR_NUMBER_OF_SCANNERS).add(1); accumulators.getLongAccumulators().get(ACCUMULATOR_NUMBER_OF_FILTERS_SCANNED).add(filtersList.size()); } KuduScannerBuilder builder = getConnection().getClient().newScannerBuilder(table); for (String fieldName : filtersList.get(0).schema().fieldNames()) { ColumnSchema columnSchema = table.getSchema().getColumn(fieldName); List<Object> columnValues = Lists.newArrayList(); for (Row filter : filtersList) { Object columnValue = RowUtils.get(filter, fieldName); columnValues.add(columnValue); } KuduPredicate predicate = KuduPredicate.newInListPredicate(columnSchema, columnValues); builder = builder.addPredicate(predicate); } KuduScanner scanner = builder.build(); return scanner; }
for (int i = 0; i < parquetSchema.getFields().size(); i++) { String colName = parquetSchema.getFields().get(i).getName(); ColumnSchema col = this.schema.getColumn(colName); String colValue = value.getValueToString(i, 0); switch (col.getType()) {
table.getSchema().getColumn("c1").getTypeAttributes().getPrecision());
table.getSchema().getColumn(oldName); } catch (IllegalArgumentException e) { LOG.info("Alter finished too quickly (old column name {} is already " + table.getSchema().getColumn(newName); fail(String.format("New column name %s should not yet be visible", newName)); } catch (IllegalArgumentException e) {} table = client.openTable(tableName); try { table.getSchema().getColumn(oldName); fail(String.format("Old column name %s should not be visible", oldName)); } catch (IllegalArgumentException e) {} table.getSchema().getColumn(newName); LOG.info("Test passed on attempt {}", i + 1); return;
final ColumnSchema column = schema.getColumn(pb.getColumn()); switch (pb.getPredicateCase()) { case EQUALITY:
table.getSchema().getColumn("value").getDesiredBlockSize()); assertEquals("wrong encoding", ColumnSchema.Encoding.PLAIN_ENCODING, table.getSchema().getColumn("value").getEncoding()); assertEquals("wrong compression algorithm", ColumnSchema.CompressionAlgorithm.NO_COMPRESSION, table.getSchema().getColumn("value").getCompressionAlgorithm()); assertEquals("wrong block size post alter", 8192, reopenedTable.getSchema().getColumn("value").getDesiredBlockSize()); assertEquals("wrong encoding post alter", ColumnSchema.Encoding.DICT_ENCODING, reopenedTable.getSchema().getColumn("value").getEncoding()); assertEquals("wrong compression algorithm post alter", ColumnSchema.CompressionAlgorithm.SNAPPY, reopenedTable.getSchema().getColumn("value").getCompressionAlgorithm());
private void checkIntPredicates(KuduTable table, NavigableSet<Long> values, List<Long> testValues) throws Exception { ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table)); for (long v : testValues) {
session.flush(); ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table));
session.flush(); ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table));
session.flush(); ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table));
session.flush(); ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table));
session.flush(); ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table));
session.flush(); ColumnSchema col = table.getSchema().getColumn("value"); Assert.assertEquals(values.size() + 1, countRows(table));