From 7640e650e5e647e6d6f3c8043c1e0a7442f154c7 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Tue, 3 May 2022 00:11:37 +0500 Subject: [PATCH] fix queries --- weed/filer/ydb/ydb_queries.go | 18 +++++++++--------- weed/filer/ydb/ydb_store.go | 4 ++-- weed/filer/ydb/ydb_store_kv.go | 8 ++++---- weed/filer/ydb/ydb_types.go | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/weed/filer/ydb/ydb_queries.go b/weed/filer/ydb/ydb_queries.go index 6e0939948..659cc2158 100644 --- a/weed/filer/ydb/ydb_queries.go +++ b/weed/filer/ydb/ydb_queries.go @@ -4,7 +4,7 @@ import asql "github.com/chrislusf/seaweedfs/weed/filer/abstract_sql" const ( insertQuery = ` - DECLARE $dir_hash int64; + DECLARE $dir_hash AS int64; DECLARE $name AS Utf8; DECLARE $directory AS Utf8; DECLARE $meta AS String; @@ -15,7 +15,7 @@ const ( ($dir_hash, $name, $directory, $meta);` updateQuery = ` - DECLARE $dir_hash int64; + DECLARE $dir_hash AS int64; DECLARE $name AS Utf8; DECLARE $directory AS Utf8; DECLARE $meta AS String; @@ -27,7 +27,7 @@ const ( COMMIT;` deleteQuery = ` - DECLARE $dir_hash int64; + DECLARE $dir_hash AS int64; DECLARE $name AS Utf8; DELETE FROM ` + asql.DEFAULT_TABLE + ` @@ -35,15 +35,15 @@ const ( COMMIT;` findQuery = ` - DECLARE $dir_hash int64; + DECLARE $dir_hash AS int64; DECLARE $name AS Utf8; SELECT meta - FROM file_meta + FROM ` + asql.DEFAULT_TABLE + ` WHERE dir_hash == $dir_hash AND name == $name;` deleteFolderChildrenQuery = ` - DECLARE $dir_hash int64; + DECLARE $dir_hash AS int64; DECLARE $directory AS Utf8; DELETE FROM ` + asql.DEFAULT_TABLE + ` @@ -51,14 +51,14 @@ const ( COMMIT;` listDirectoryQuery = ` - DECLARE $dir_hash int64; + DECLARE $dir_hash AS int64; DECLARE $directory AS Utf8; DECLARE $start_name AS Utf8; DECLARE $prefix AS Utf8; - DECLARE $limit AS int64; + DECLARE $limit AS Uint64; SELECT name, meta FROM ` + asql.DEFAULT_TABLE + ` - WHERE dir_hash == $dir_hash AND directory == $directory and name %s $start_name and name LIKE '$prefix%%' + WHERE dir_hash == $dir_hash AND directory == $directory and name %s $start_name and name LIKE $prefix ORDER BY name ASC LIMIT $limit;` ) diff --git a/weed/filer/ydb/ydb_store.go b/weed/filer/ydb/ydb_store.go index 8e0815009..6d6389dde 100644 --- a/weed/filer/ydb/ydb_store.go +++ b/weed/filer/ydb/ydb_store.go @@ -228,8 +228,8 @@ func (store *YdbStore) ListDirectoryPrefixedEntries(ctx context.Context, dirPath table.ValueParam("$dir_hash", types.Int64Value(util.HashStringToLong(dir))), table.ValueParam("$directory", types.UTF8Value(dir)), table.ValueParam("$start_name", types.UTF8Value(startFileName)), - table.ValueParam("$prefix", types.UTF8Value(prefix)), - table.ValueParam("$limit", types.Int64Value(limit)), + table.ValueParam("$prefix", types.UTF8Value(prefix+"%")), + table.ValueParam("$limit", types.Uint64Value(uint64(limit))), ) err = store.doTxOrDB(ctx, &queryWithPragma, queryParams, roTX, func(res result.Result) error { defer func() { diff --git a/weed/filer/ydb/ydb_store_kv.go b/weed/filer/ydb/ydb_store_kv.go index d679d7246..069c35224 100644 --- a/weed/filer/ydb/ydb_store_kv.go +++ b/weed/filer/ydb/ydb_store_kv.go @@ -17,11 +17,11 @@ func (store *YdbStore) KvPut(ctx context.Context, key []byte, value []byte) (err return store.DB.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) { stmt, err := s.Prepare(ctx, withPragma(store.getPrefix(ctx, dirStr), insertQuery)) if err != nil { - return fmt.Errorf("Prepare %s: %v", util.NewFullPath(dirStr, name).Name(), err) + return fmt.Errorf("kv put prepare %s: %v", util.NewFullPath(dirStr, name).Name(), err) } _, _, err = stmt.Execute(ctx, rwTX, fileMeta.queryParameters()) if err != nil { - return fmt.Errorf("kv put %s: %v", util.NewFullPath(dirStr, name).Name(), err) + return fmt.Errorf("kv put execute %s: %v", util.NewFullPath(dirStr, name).Name(), err) } return nil }) @@ -33,13 +33,13 @@ func (store *YdbStore) KvGet(ctx context.Context, key []byte) (value []byte, err err = store.DB.Table().Do(ctx, func(ctx context.Context, s table.Session) error { stmt, err := s.Prepare(ctx, withPragma(store.getPrefix(ctx, dirStr), findQuery)) if err != nil { - return fmt.Errorf("Prepare %s: %v", util.NewFullPath(dirStr, name), err) + return fmt.Errorf("kv get prepare %s: %v", util.NewFullPath(dirStr, name), err) } _, res, err := stmt.Execute(ctx, roTX, table.NewQueryParameters( table.ValueParam("$dir_hash", types.Int64Value(dirHash)), table.ValueParam("$name", types.UTF8Value(name)))) if err != nil { - return fmt.Errorf("kv get %s: %v", util.NewFullPath(dirStr, name).Name(), err) + return fmt.Errorf("kv get execute %s: %v", util.NewFullPath(dirStr, name).Name(), err) } defer func() { _ = res.Close() }() for res.NextRow() { diff --git a/weed/filer/ydb/ydb_types.go b/weed/filer/ydb/ydb_types.go index 4194afbc8..07e69e6a5 100644 --- a/weed/filer/ydb/ydb_types.go +++ b/weed/filer/ydb/ydb_types.go @@ -13,7 +13,7 @@ type FileMeta struct { DirHash int64 `ydb:"type:int64"` Name string `ydb:"type:utf8"` Directory string `ydb:"type:utf8"` - Meta []byte `ydb:"-"` + Meta []byte `ydb:"type:string"` } //ydb:gen scan,value @@ -29,7 +29,7 @@ func (fm *FileMeta) queryParameters() *table.QueryParameters { func createTableOptions() []options.CreateTableOption { return []options.CreateTableOption{ - options.WithColumn("dir_hash", types.Optional(types.TypeUint64)), + options.WithColumn("dir_hash", types.Optional(types.TypeInt64)), options.WithColumn("name", types.Optional(types.TypeUTF8)), options.WithColumn("directory", types.Optional(types.TypeUTF8)), options.WithColumn("meta", types.Optional(types.TypeString)),