【问题标题】:How to store multidimensional array in cassandra and hive如何在cassandra和hive中存储多维数组
【发布时间】:2022-01-16 21:29:58
【问题描述】:

所以,我按照这个例子:

https://keras.io/examples/nlp/pretrained_word_embeddings/

在此示例中,在以下部分中生成嵌入矩阵

num_tokens = len(voc) + 2
embedding_dim = 100
hits = 0
misses = 0

# Prepare embedding matrix
embedding_matrix = np.zeros((num_tokens, embedding_dim))
for word, i in word_index.items():
    embedding_vector = embeddings_index.get(word)
    if embedding_vector is not None:
        # Words not found in embedding index will be all-zeros.
        # This includes the representation for "padding" and "OOV"
        embedding_matrix[i] = embedding_vector
        hits += 1
    else:
        misses += 1
print("Converted %d words (%d misses)" % (hits, misses))

如何将其推送到 cassandra 和 hive。我试过以下查询:

statement = "CREATE TABLE schema.upcoming_calendar3 ( embedding_matrix list>, PRIMARY KEY ( embedding_matrix) );"

但是,这给了我以下错误:

InvalidRequest:来自服务器的错误:code=2200 [Invalid query] message="Invalid non-frozen collection type for PRIMARY KEY component embedding_matrix"

同样,我也想将它发送到 hive。

任何关于在 cassandra 和 hive 中使用什么数据类型的帮助以及将其发送到数据库的更有效方式都会很棒。

目前,我正在推送这样的数据:

statement = "插入 schema.upcoming_calendar3(embedding_matrix) 值 (%s);" % (embedding_matrix)

【问题讨论】:

    标签: python hive cassandra tensorflow2.0


    【解决方案1】:

    像这样将上层集合声明为冻结:

    embedding_matrix frozen<list<set<text>>>

    如果您想将其用作主键。

    在hive中对应的数据类型是array<array<type>>,见manual

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2021-12-05
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      相关资源
      最近更新 更多