插入数据
更新时间:
数据识别方式
您可以通过明文或者编码方式向向量列写入数据或者查询向量列数据。
注意:必须使用单引号将数据引用起来,数据的维数与定义向量列时指定的维度相同。
明文:
'[1,2,3,4]'或者'{1.0,2.0,3.0,4.0}'Base64编码:
'MTIzNA=='以下使用Base64解码完成byte[]数据类型和float[]数据类型的解码。
public static String getBase64(float array[]) {ByteBuffer bb = ByteBuffer.allocate(array.length * 4);bb.order(ByteOrder.LITTLE_ENDIAN);for(int i = 0; i < array.length; i++) {bb.putFloat(array[i]);}return Base64.getEncoder().encodeToString(bb.array());}public static float[] decodeBase64(String str) {byte[] buf = Base64.getDecoder().decode(str);ByteBuffer bb = ByteBuffer.wrap(buf);bb.order(ByteOrder.LITTLE_ENDIAN);float[] ret = new float[buf.length / 4];for(int i = 0; i < ret.length; i++) {ret[i] = bb.getFloat();}return ret;}
插入数据
您可以通过INSERT语句向向量表中插入数据,通过DELETE删除数据。例如,通过以下SQL向TEST_TABLE表中插入两条数据。
注意:向向量表中插入数据时,向量列的维数必须与定义向量列时指定的维度相同,否则系统将提示出错。
insert into test_table values('rowkey1', '[0.5,0.6,0.3,0.1]','seednmae', 'label')insert into test_table values('rowkey1', 'AAAAP5qZGT+amZk+zczMPQ==','seedname', 'label')
该文章对您有帮助吗?