Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data_loaderを使ってテーブルにデータを投入する際に一部のカラムのみデータを入力した状態でもINSERTしたい #186

Closed
scalar-kato opened this issue Apr 13, 2021 · 4 comments
Assignees

Comments

@scalar-kato
Copy link

Is your feature request related to a problem? Please describe.
例として以下のようなテーブルに対して

id name tel

id,nameのみをデータ入力したINSERT文を用意してデータ投入を行いたい。現状はテーブルに定義された全てのカラムに対してデータを用意する必要がある。

Describe the solution you'd like
data_loaderを使ってテーブルにデータを投入する際に一部のカラムのみデータを入力した状態でもINSERTしたい

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@scalarindetail scalarindetail self-assigned this Apr 14, 2021
@scalarindetail
Copy link
Contributor

@scalar-kato
結果
テストしたところ、テーブルのフォーマットとデータのフォーマットが異なる場合、エラーが発生しました, それ以外は問題ありませんでした。Scalardb 2.x.x, と 3.0.0 使用した.

動けるのやり方

// table_format.json
{
  "test.sample": {
    "transaction": true,
    "partition-key": [
      "c1"
    ],
    "clustering-key": [
      "c2"
    ],
    "columns": {
      "c1": "TEXT",
      "c2": "TEXT"
    }
  }
}
// data.json
[{
  "c1": "foo",
  "c2": "bar"
}]
それとも
[{
  "c1": "foo",
  "c2": "bar",
  "c3": "",
}]
// 実行するのコマンド
build/install/data_loader/bin/data_loader --properties=src/main/resources/scalardb.properties --table-schema=src/main/resources/table.json --data-file=src/main/resources/data.json
// データベースで
 c1       | c2   | before_c2 | before_c3 | before_tx_committed_at | before_tx_id | before_tx_prepared_at | before_tx_state | before_tx_version | c3   | tx_committed_at | tx_id                                | tx_prepared_at | tx_state | tx_version
----------+------+-----------+-----------+------------------------+--------------+-----------------------+-----------------+-------------------+------+-----------------+--------------------------------------+----------------+----------+------------
      sad | help |      null |      null |                   null |         null |                  null |            null |              null |      |   1618371834744 | d5c177a5-4c5d-4ef2-8867-41e87b95cad3 |  1618371834607 |        3 |          1
    sadss | help |      null |      null |                   null |         null |                  null |            null |              null |  123 |   1618372084147 | 5514574a-f89e-460b-af82-d373d1a4eb3d |  1618372084088 |        3 |          1
   sadss1 | help |      null |      null |                   null |         null |                  null |            null |              null |      |   1618372097629 | 10ea2783-a998-4214-abad-7b393dbab87f |  1618372097560 |        3 |          1
 sadss112 | help |      null |      null |                   null |         null |                  null |            null |              null | null |   1618372289174 | a26b5bde-eb83-4009-ae55-e8b2b86225d1 |  1618372289122 |        3 |          1
  sadss11 | help |      null |      null |                   null |         null |                  null |            null |              null | null |   1618372223439 | aa941be1-b98c-491a-b243-327f126da6f3 |  1618372223381 |        3 |          1

Additional Context
因みに、どのようにしてデータベースにデータを挿入するのかを知りたいのですが、データやテーブルのフォーマットを見せてもいいんですか?

また、どのようにしてエラーをリプロデュースすることができますか?

@scalar-kato
Copy link
Author

@scalarindetail
実際のテーブルではないですが、例えばこのようなテーブル構成でテーブルを作成し、

// table_format.json
{
  "test.sample": {
    "transaction": true,
    "partition-key": [
      "c1"
    ],
    "clustering-key": [
      "c2"
    ],
    "columns": {
      "c1": "TEXT",
      "c2": "TEXT",
      "c3": "TEXT",
      "c4": "TEXT"
    }
  }
}

下のようなデータ挿入を行いたいです。
今はエラーになると思います。

// data1.json
[{
  "c1": "foo",
  "c2": "bar"
}]

挿入するデータを下のようにするとエラーが起こらないことは把握していますが、私たちがやりたいことはdata1.jsonのやり方です。

// data2.json
[{
  "c1": "foo",
  "c2": "bar",
  "c3": "hoge",
  "c4": "hogehoge",
}]

@scalarindetail
Copy link
Contributor

scalarindetail commented Apr 14, 2021

@scalar-kato
なるほど、そ言えば、data loaderのソースコードを修正が必要です。

@feeblefakie
Copy link
Contributor

The existing data loader is obsolete and not maintained anymore. We are working on a new data loader, so please wait for a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants