Java源码示例:com.alicloud.openservices.tablestore.model.Column
示例1
public static GridDataSetMeta parseMetaFromRow(Row row) {
String uniqueKey = row.getPrimaryKey().getPrimaryKeyColumn(GRID_DATA_SET_ID_PK_NAME).getValue().asString();
DataType dataType = DataType.getType(row.getColumn(DATA_TYPE_COL_NAME).get(0).getValue().asString());
List<String> variables = Arrays.asList(row.getColumn(VARIABLE_LIST_COL_NAME).get(0).getValue().asString().split(","));
int tSize = (int) row.getColumn(T_SIZE_COL_NAME).get(0).getValue().asLong();
int zSize = (int) row.getColumn(Z_SIZE_COL_NAME).get(0).getValue().asLong();
int xSize = (int) row.getColumn(X_SIZE_COL_NAME).get(0).getValue().asLong();
int ySize = (int) row.getColumn(Y_SIZE_COL_NAME).get(0).getValue().asLong();
StoreOptions.StoreType storeType = StoreOptions.StoreType.valueOf(
row.getColumn(STORE_TYPE_COL_NAME).get(0).getValue().asString());
StoreOptions storeOptions = new StoreOptions(storeType);
if (storeType.equals(StoreOptions.StoreType.SLICE)) {
storeOptions.setxSplitCount((int) row.getColumn(X_SPLIT_COUNT_COL_NAME).get(0).getValue().asLong());
storeOptions.setySplitCount((int) row.getColumn(Y_SPLIT_COUNT_COL_NAME).get(0).getValue().asLong());
}
Map<String, Object> attributes = new HashMap<String, Object>();
for (Column column : row.getColumns()) {
if (!column.getName().startsWith("_")) {
attributes.put(column.getName(), ValueUtil.toObject(column.getValue()));
}
}
GridDataSetMeta meta = new GridDataSetMeta(uniqueKey, dataType, variables, tSize, zSize, xSize, ySize, storeOptions);
meta.setAttributes(attributes);
return meta;
}
示例2
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
List<Map.Entry<String,Column>> list = new ArrayList<Map.Entry<String,Column>>(fields.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String,Column>>(){
@Override
public int compare(Map.Entry<String, Column> o1, Map.Entry<String, Column> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String,Column> entry : list) {
if (sb.length() != 0) {
sb.append(", ");
}
sb.append(entry.getValue().getName() + ":" + entry.getValue().getValue());
}
return sb.toString();
}
示例3
/**
* insert meta into metaTable
* */
private static void insertMeta() {
for (int i = 0; i < 10; i++) {
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_" + i)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("groupName", "表格存储" + i)
.setField("createTime", i)
.setField("location", "30,12" + i)
.setField("isPublic", i % 2 == 0)
.setField("point", i + 0.0D)
.setField(new Column("tags", ColumnValue.fromString("[\"Table\",\"Store\"]")));
metaService.insert(insertGroup);
}
}
示例4
/**
* insert meta into metaTable
* */
private static void insertMeta() {
for (int i = 0; i < 10; i++) {
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_" + i)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("groupName", "表格存储" + i)
.setField("createTime", i)
.setField("location", "30,12" + i)
.setField("isPublic", i % 2 == 0)
.setField("point", i + 0.0D)
.setField(new Column("tags", ColumnValue.fromString("[\"Table\",\"Store\"]")));
metaService.insert(insertGroup);
}
}
示例5
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
List<Map.Entry<String,Column>> list = new ArrayList<Map.Entry<String,Column>>(fields.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String,Column>>(){
@Override
public int compare(Map.Entry<String, Column> o1, Map.Entry<String, Column> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String,Column> entry : list) {
if (sb.length() != 0) {
sb.append(", ");
}
sb.append(entry.getValue().getName() + ":" + entry.getValue().getValue());
}
return sb.toString();
}
示例6
@Override
public ReadRecordsResponse readRecords(ReadRecordsRequest request) throws TableStoreException, ClientException {
ReadRecordsResponse resp = new ReadRecordsResponse();
List<StreamRecord> recordList = new ArrayList<StreamRecord>();
for (int i = 0; i < 100; i++) {
StreamRecord record = new StreamRecord();
record.setRecordType(StreamRecord.RecordType.PUT);
record.setPrimaryKey(new PrimaryKey(Arrays.asList(new PrimaryKeyColumn("pk", PrimaryKeyValue.fromLong(i)))));
record.setColumns(Arrays.asList(new RecordColumn(new Column("col", ColumnValue.fromLong(i), i), RecordColumn.ColumnType.PUT)));
recordList.add(record);
}
resp.setRecords(recordList);
if (finishedChannels.contains(request.getChannelId())) {
resp.setNextToken(FINISH_TAG);
} else {
resp.setNextToken("token");
}
resp.setMemoizedSerializedSize(102400);
return resp;
}
示例7
static List<RowPutChange> putRows(SyncClient client, String tableName) {
List<RowPutChange> changes = new ArrayList<RowPutChange>();
for (int i = 0; i < 1000; i++) {
PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("int", PrimaryKeyValue.fromLong(i));
primaryKeyBuilder.addPrimaryKeyColumn("str", PrimaryKeyValue.fromString("string" + i));
RowPutChange rowPutChange = new RowPutChange(tableName, primaryKeyBuilder.build());
for (int j = 0; j < 10; j++) {
rowPutChange.addColumn(new Column("test" + j, ColumnValue.fromLong(i)));
}
client.putRow(new PutRowRequest(rowPutChange));
changes.add(rowPutChange);
}
System.out.println("Put 1000 rows succeed.");
return changes;
}
示例8
/**
* insert meta into metaTable
* */
private static void insertMeta() {
for (int i = 0; i < 10; i++) {
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_" + i)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("groupName", "表格存储" + i)
.setField("createTime", i)
.setField("location", "30,12" + i)
.setField("isPublic", i % 2 == 0)
.setField("point", i + 0.0D)
.setField(new Column("tags", ColumnValue.fromString("[\"Table\",\"Store\"]")));
metaService.insert(insertGroup);
}
}
示例9
/**
* insert meta into metaTable
* */
private static void insertMeta() {
for (int i = 0; i < 10; i++) {
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_" + i)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("groupName", "表格存储" + i)
.setField("createTime", i)
.setField("location", "30,12" + i)
.setField("isPublic", i % 2 == 0)
.setField("point", i + 0.0D)
.setField(new Column("tags", ColumnValue.fromString("[\"Table\",\"Store\"]")));
metaService.insert(insertGroup);
}
}
示例10
@SuppressWarnings("unchecked")
private static <T> T getLatestColumnValue(Row row, String name, Class<T> valueType) {
Column column = row.getLatestColumn(name);
if (String.class == valueType) {
return (T) column.getValue().asString();
} else if (Long.class == valueType || long.class == valueType) {
return (T) Long.valueOf(column.getValue().asLong());
} else if (boolean.class == valueType || Boolean.class == valueType) {
return (T) Boolean.valueOf(column.getValue().asBoolean());
} else if (double.class == valueType || Double.class == valueType) {
return (T) Double.valueOf(column.getValue().asDouble());
}
throw new UnsupportedOperationException("Unknown type " + valueType);
}
示例11
public List<Column> getColumns(StreamRecord record) {
List<Column> retColumns = new ArrayList<Column>();
for (RecordColumn column : record.getColumns()) {
retColumns.add(column.getColumn());
}
return retColumns;
}
示例12
/**
* Set field with value of string list type, replace old value if it is exist.
*
* @param columns list of field
* @return this
*/
@SuppressWarnings("unchecked")
public T setFields(List<Column> columns) {
for (Column column : columns) {
fields.put(column.getName(), column);
}
return (T)this;
}
示例13
@Test
public void testInsertMeta() {
TimelineMetaStore metaService = wrapper.getMetaStore();
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_a")
.addField("long", 1000L)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("Long", 1000L)
.setField("double", 1.1)
.setField("groupName", "tablestore")
.setField("boolean", true)
.setField(new Column("stringList", ColumnValue.fromString("[\"stringList\"]")));
metaService.insert(insertGroup);
TimelineMeta readGroup = metaService.read(identifier);
assertNotNull(readGroup);
assertTrue(identifier.equals(readGroup.getIdentifier()));
assertEquals(1.1, readGroup.getDouble("double"), 0.001);
assertEquals("tablestore", readGroup.getString("groupName"));
assertEquals(1000L, readGroup.getLong("Long"));
assertEquals(true, readGroup.getBoolean("boolean"));
assertEquals(1, readGroup.getStringList("stringList").size());
assertEquals("stringList", readGroup.getStringList("stringList").get(0));
metaService.delete(identifier);
try {
insertGroup.setField(LONG_INVALID_COLUME_NAME, "invalid");
metaService.insert(insertGroup);
} catch (Exception e) {
assertTrue(e instanceof TimelineException);
assertEquals("OTSParameterInvalid", e.getMessage());
}
}
示例14
@Test
public void testDeleteMeta() {
TimelineMetaStore metaService = wrapper.getMetaStore();
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_delete")
.addField("long", 1000L)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("Long", 1000L)
.setField("double", 1.1)
.setField("groupName", "tablestore")
.setField("boolean", true)
.setField(new Column("stringList", ColumnValue.fromString("[\"stringList\"]")));
metaService.insert(insertGroup);
TimelineMeta readGroup = metaService.read(identifier);
assertNotNull(readGroup);
metaService.delete(identifier);
readGroup = metaService.read(identifier);
assertNull(readGroup);
try {
metaService.delete(identifier);
} catch (Exception e) {
fail();
}
}
示例15
private TimelineMeta getMeta() {
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("p0", "key").build();
TimelineMeta meta = new TimelineMeta(identifier);
meta.setField("c0", "hello world");
meta.setField("c1", true);
meta.setField("c2", 9.99);
meta.setField("c3", 20190418);
meta.setField("c4", new String[]{"a", "b", "c", "d", "e"});
meta.setField("c5", Arrays.asList("0", "1", "2", "3", "4"));
meta.setField(new Column("c6", ColumnValue.fromLong(9999)));
return meta;
}
示例16
private TimelineMessage getMessage() {
TimelineMessage message = new TimelineMessage();
message.setField("c0", "hello world");
message.setField("c1", true);
message.setField("c2", 9.99);
message.setField("c3", 20190418);
message.setField("c4", new String[]{"a", "b", "c", "d", "e"});
message.setField("c5", Arrays.asList("0", "1", "2", "3", "4"));
message.setField(new Column("c6", ColumnValue.fromLong(9999)));
return message;
}
示例17
public Builder(long timestamp, TimeUnit unit) {
if (timestamp < 0) {
throw new ClientException("The timestamp must be positive.");
}
this.timestamp = unit.toMicros(timestamp);
this.fieldList = new ArrayList<Column>();
}
示例18
public Builder addField(String key, float value) {
this.fieldList.add(
new Column(
key,
ColumnValue.fromDouble(value)));
return this;
}
示例19
public Builder addField(String key, double value) {
this.fieldList.add(
new Column(
key,
ColumnValue.fromDouble(value)));
return this;
}
示例20
public Builder addField(String key, int value) {
this.fieldList.add(
new Column(
key,
ColumnValue.fromLong(value)));
return this;
}
示例21
public Builder addField(String key, long value) {
this.fieldList.add(
new Column(
key,
ColumnValue.fromLong(value)));
return this;
}
示例22
public Builder addField(String key, String value) {
this.fieldList.add(
new Column(
key,
ColumnValue.fromString(value)));
return this;
}
示例23
public Builder addField(String key, boolean value) {
this.fieldList.add(
new Column(
key,
ColumnValue.fromBoolean(value)));
return this;
}
示例24
public ColumnValue getField(String name) {
ColumnValue value = null;
for (Column col : this.fieldList) {
if (col.getName().equals(name)) {
value = col.getValue();
}
}
return value;
}
示例25
public String toString() {
Map<String, Object> fields = new HashMap<String, Object>();
for (Column col : this.fieldList) {
fields.put(col.getName(), col.getValue().toString());
}
StringBuilder sb = new StringBuilder();
sb.append("timestamp=").append(timestamp).append(", ");
sb.append("fileds=").append(fields);
return sb.toString();
}
示例26
/**
* Set field with value of string list type, replace old value if it is exist.
*
* @param columns list of field
* @return this
*/
@SuppressWarnings("unchecked")
public T setFields(List<Column> columns) {
for (Column column : columns) {
fields.put(column.getName(), column);
}
return (T)this;
}
示例27
@Test
public void testInsertMeta() {
TimelineMetaStore metaService = wrapper.getMetaStore();
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_a")
.addField("long", 1000L)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("Long", 1000L)
.setField("double", 1.1)
.setField("groupName", "tablestore")
.setField("boolean", true)
.setField(new Column("stringList", ColumnValue.fromString("[\"stringList\"]")));
metaService.insert(insertGroup);
TimelineMeta readGroup = metaService.read(identifier);
assertNotNull(readGroup);
assertTrue(identifier.equals(readGroup.getIdentifier()));
assertEquals(1.1, readGroup.getDouble("double"), 0.001);
assertEquals("tablestore", readGroup.getString("groupName"));
assertEquals(1000L, readGroup.getLong("Long"));
assertEquals(true, readGroup.getBoolean("boolean"));
assertEquals(1, readGroup.getStringList("stringList").size());
assertEquals("stringList", readGroup.getStringList("stringList").get(0));
metaService.delete(identifier);
try {
insertGroup.setField(LONG_INVALID_COLUME_NAME, "invalid");
metaService.insert(insertGroup);
} catch (Exception e) {
assertTrue(e instanceof TimelineException);
assertEquals("OTSParameterInvalid", e.getMessage());
}
}
示例28
@Test
public void testDeleteMeta() {
TimelineMetaStore metaService = wrapper.getMetaStore();
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("timelineId", "group_delete")
.addField("long", 1000L)
.build();
TimelineMeta insertGroup = new TimelineMeta(identifier)
.setField("Long", 1000L)
.setField("double", 1.1)
.setField("groupName", "tablestore")
.setField("boolean", true)
.setField(new Column("stringList", ColumnValue.fromString("[\"stringList\"]")));
metaService.insert(insertGroup);
TimelineMeta readGroup = metaService.read(identifier);
assertNotNull(readGroup);
metaService.delete(identifier);
readGroup = metaService.read(identifier);
assertNull(readGroup);
try {
metaService.delete(identifier);
} catch (Exception e) {
fail();
}
}
示例29
private TimelineMeta getMeta() {
TimelineIdentifier identifier = new TimelineIdentifier.Builder()
.addField("p0", "key").build();
TimelineMeta meta = new TimelineMeta(identifier);
meta.setField("c0", "hello world");
meta.setField("c1", true);
meta.setField("c2", 9.99);
meta.setField("c3", 20190418);
meta.setField("c4", new String[]{"a", "b", "c", "d", "e"});
meta.setField("c5", Arrays.asList("0", "1", "2", "3", "4"));
meta.setField(new Column("c6", ColumnValue.fromLong(9999)));
return meta;
}
示例30
private TimelineMessage getMessage() {
TimelineMessage message = new TimelineMessage();
message.setField("c0", "hello world");
message.setField("c1", true);
message.setField("c2", 9.99);
message.setField("c3", 20190418);
message.setField("c4", new String[]{"a", "b", "c", "d", "e"});
message.setField("c5", Arrays.asList("0", "1", "2", "3", "4"));
message.setField(new Column("c6", ColumnValue.fromLong(9999)));
return message;
}