文档

插入数据

更新时间:

数据识别方式

您可以通过明文或者编码方式向向量列写入数据或者查询向量列数据。

注意:必须使用单引号将数据引用起来,数据的维数与定义向量列时指定的维度相同。

  • 明文:'[1,2,3,4]'或者'{1.0,2.0,3.0,4.0}'

  • Base64编码:'MTIzNA=='

    以下使用Base64解码完成byte[]数据类型和float[]数据类型的解码。

    1. public static String getBase64(float array[]) {
    2. ByteBuffer bb = ByteBuffer.allocate(array.length * 4);
    3. bb.order(ByteOrder.LITTLE_ENDIAN);
    4. for(int i = 0; i < array.length; i++) {
    5. bb.putFloat(array[i]);
    6. }
    7. return Base64.getEncoder().encodeToString(bb.array());
    8. }
    9. public static float[] decodeBase64(String str) {
    10. byte[] buf = Base64.getDecoder().decode(str);
    11. ByteBuffer bb = ByteBuffer.wrap(buf);
    12. bb.order(ByteOrder.LITTLE_ENDIAN);
    13. float[] ret = new float[buf.length / 4];
    14. for(int i = 0; i < ret.length; i++) {
    15. ret[i] = bb.getFloat();
    16. }
    17. return ret;
    18. }

插入数据

您可以通过INSERT语句向向量表中插入数据,通过DELETE删除数据。例如,通过以下SQL向TEST_TABLE表中插入两条数据。

注意:向向量表中插入数据时,向量列的维数必须与定义向量列时指定的维度相同,否则系统将提示出错。

  1. insert into test_table values('rowkey1', '[0.5,0.6,0.3,0.1]','seednmae', 'label')
  2. insert into test_table values('rowkey1', 'AAAAP5qZGT+amZk+zczMPQ==','seedname', 'label'
  • 本页导读 (1)
文档反馈