Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_oceanbase
提交
1de9c636
S
skill_tree_oceanbase
项目概览
CSDN 技术社区
/
skill_tree_oceanbase
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1de9c636
编写于
11月 05, 2021
作者:
M
Mars Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add pid; ensure node id if no
上级
2221abbc
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
87 addition
and
18 deletion
+87
-18
data/1.OceanBase初阶/2.基本操作/7.查询数据/children.json
data/1.OceanBase初阶/2.基本操作/7.查询数据/children.json
+6
-0
data/1.OceanBase初阶/2.基本操作/7.查询数据/children.md
data/1.OceanBase初阶/2.基本操作/7.查询数据/children.md
+43
-0
data/1.OceanBase初阶/2.基本操作/7.查询数据/config.json
data/1.OceanBase初阶/2.基本操作/7.查询数据/config.json
+3
-1
data/2.OceanBase中阶/3.表查询/config.json
data/2.OceanBase中阶/3.表查询/config.json
+3
-1
data/3.OceanBase高阶/3.编程和查询/2.连接查询/config.json
data/3.OceanBase高阶/3.编程和查询/2.连接查询/config.json
+3
-1
src/tree.py
src/tree.py
+29
-15
未找到文件。
data/1.OceanBase初阶/2.基本操作/7.查询数据/children.json
0 → 100644
浏览文件 @
1de9c636
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"children.md"
}
\ No newline at end of file
data/1.OceanBase初阶/2.基本操作/7.查询数据/children.md
0 → 100644
浏览文件 @
1de9c636
# 查找子节点
有一个表 node,有两列
```
shell
# select item from node;
id
| pid
------------------
1 | 0
2 | 1
3 | 1
4 | 3
5 | 2
...
```
其中id是自增主键,pid指向父节点的id。那么给定某一个id ,查找它的子节点的查询应该是:
## 答案
```
sql
select
*
from
node
where
pid
=
?
```
## 选项
### 缺少 where
```
sql
select
*
from
node
pid
=
?
```
### 结构错误
```
sql
from
node
select
*
where
pid
=
?
```
### select 不完整
```
sql
select
from
node
where
pid
=
?
```
data/1.OceanBase初阶/2.基本操作/7.查询数据/config.json
浏览文件 @
1de9c636
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
"node_id"
:
"oceanbase-6f727423ee414b85b6ed90bebcdd88b8"
,
"node_id"
:
"oceanbase-6f727423ee414b85b6ed90bebcdd88b8"
,
"title"
:
"查询数据"
,
"title"
:
"查询数据"
,
"export"
:
[
"export"
:
[
"hello.json"
"hello.json"
,
"children.json"
]
]
}
}
\ No newline at end of file
data/2.OceanBase中阶/3.表查询/config.json
浏览文件 @
1de9c636
{
{
"keywords"
:
[],
"keywords"
:
[],
"node_id"
:
"oceanbase-641f612acf59456187b9573a4398e20b"
,
"node_id"
:
"oceanbase-641f612acf59456187b9573a4398e20b"
,
"title"
:
"表查询"
"title"
:
"表查询"
,
"export"
:
[]
}
}
\ No newline at end of file
data/3.OceanBase高阶/3.编程和查询/2.连接查询/config.json
浏览文件 @
1de9c636
{
{
"keywords"
:
[],
"keywords"
:
[],
"node_id"
:
"oceanbase-d28015752f834bffacc6dfb9ab64b8c2"
,
"node_id"
:
"oceanbase-d28015752f834bffacc6dfb9ab64b8c2"
,
"title"
:
"连接查询"
"title"
:
"连接查询"
,
"export"
:
[]
}
}
\ No newline at end of file
src/tree.py
浏览文件 @
1de9c636
import
logging
from
genericpath
import
exists
from
genericpath
import
exists
import
json
import
json
import
os
import
os
...
@@ -7,6 +8,9 @@ import re
...
@@ -7,6 +8,9 @@ import re
id_set
=
set
()
id_set
=
set
()
logger
=
logging
.
getLogger
(
__name__
)
def
load_json
(
p
):
def
load_json
(
p
):
with
open
(
p
,
'r'
)
as
f
:
with
open
(
p
,
'r'
)
as
f
:
return
json
.
loads
(
f
.
read
())
return
json
.
loads
(
f
.
read
())
...
@@ -18,13 +22,22 @@ def dump_json(p, j, exist_ok=False, override=False):
...
@@ -18,13 +22,22 @@ def dump_json(p, j, exist_ok=False, override=False):
if
not
override
:
if
not
override
:
return
return
else
:
else
:
print
(
f
"
{
p
}
already exist"
)
logger
.
error
(
f
"
{
p
}
already exist"
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
with
open
(
p
,
'w+'
)
as
f
:
with
open
(
p
,
'w+'
)
as
f
:
f
.
write
(
json
.
dumps
(
j
,
indent
=
2
,
ensure_ascii
=
False
))
f
.
write
(
json
.
dumps
(
j
,
indent
=
2
,
ensure_ascii
=
False
))
def
ensure_config
(
path
):
config_path
=
os
.
path
.
join
(
path
,
"config.json"
)
if
not
os
.
path
.
exists
(
config_path
):
node
=
{
"keywords"
:
[]}
dump_json
(
config_path
,
node
,
exist_ok
=
True
,
override
=
False
)
return
node
else
:
return
load_json
(
config_path
)
def
parse_no_name
(
d
):
def
parse_no_name
(
d
):
p
=
r
'(\d+)\.(.*)'
p
=
r
'(\d+)\.(.*)'
m
=
re
.
search
(
p
,
d
)
m
=
re
.
search
(
p
,
d
)
...
@@ -37,6 +50,7 @@ def parse_no_name(d):
...
@@ -37,6 +50,7 @@ def parse_no_name(d):
return
no
,
dir_name
return
no
,
dir_name
def
check_export
(
base
,
cfg
):
def
check_export
(
base
,
cfg
):
flag
=
False
flag
=
False
exports
=
[]
exports
=
[]
...
@@ -70,7 +84,7 @@ def gen_tree(data_path):
...
@@ -70,7 +84,7 @@ def gen_tree(data_path):
flag
=
False
flag
=
False
if
(
node
.
get
(
'node_id'
)
is
None
)
or
node
.
get
(
'node_id'
)
in
id_set
:
if
(
node
.
get
(
'node_id'
)
is
None
)
or
node
.
get
(
'node_id'
)
in
id_set
:
node
[
'node_id'
]
=
gen_node_id
()
node
[
'node_id'
]
=
gen_node_id
()
flag
=
True
flag
=
True
id_set
.
add
(
node
[
'node_id'
])
id_set
.
add
(
node
[
'node_id'
])
...
@@ -78,7 +92,7 @@ def gen_tree(data_path):
...
@@ -78,7 +92,7 @@ def gen_tree(data_path):
if
'children'
in
node
:
if
'children'
in
node
:
for
c
in
node
[
"children"
]:
for
c
in
node
[
"children"
]:
flag
=
flag
or
ensure_id_helper
(
list
(
c
.
values
())[
0
])
flag
=
flag
or
ensure_id_helper
(
list
(
c
.
values
())[
0
])
return
flag
return
flag
def
ensure_node_id
(
cfg
):
def
ensure_node_id
(
cfg
):
...
@@ -97,7 +111,7 @@ def gen_tree(data_path):
...
@@ -97,7 +111,7 @@ def gen_tree(data_path):
if
'children'
in
node
:
if
'children'
in
node
:
for
c
in
node
[
"children"
]:
for
c
in
node
[
"children"
]:
flag
=
flag
or
ensure_title_helper
(
list
(
c
.
values
())[
0
],
None
,
list
(
c
.
keys
())[
0
])
flag
=
flag
or
ensure_title_helper
(
list
(
c
.
values
())[
0
],
None
,
list
(
c
.
keys
())[
0
])
return
flag
return
flag
def
ensure_title
(
cfg
,
cfg_path
):
def
ensure_title
(
cfg
,
cfg_path
):
...
@@ -114,11 +128,11 @@ def gen_tree(data_path):
...
@@ -114,11 +128,11 @@ def gen_tree(data_path):
return
node
,
node_children
return
node
,
node_children
# 根节点
# 根节点
cfg
=
ensure_config
(
data_path
)
cfg_path
=
os
.
path
.
join
(
data_path
,
'config.json'
)
cfg_path
=
os
.
path
.
join
(
data_path
,
'config.json'
)
cfg
=
load_json
(
cfg_path
)
if
ensure_node_id
(
cfg
):
if
ensure_node_id
(
cfg
):
dump_json
(
cfg_path
,
cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
cfg_path
,
cfg
,
exist_ok
=
True
,
override
=
True
)
if
ensure_title
(
cfg
,
cfg_path
):
if
ensure_title
(
cfg
,
cfg_path
):
cfg
[
"title"
]
=
"C"
cfg
[
"title"
]
=
"C"
dump_json
(
cfg_path
,
cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
cfg_path
,
cfg
,
exist_ok
=
True
,
override
=
True
)
...
@@ -134,7 +148,7 @@ def gen_tree(data_path):
...
@@ -134,7 +148,7 @@ def gen_tree(data_path):
print
(
level_no_dir
)
print
(
level_no_dir
)
no
,
level_name
=
parse_no_name
(
level_no_name
)
no
,
level_name
=
parse_no_name
(
level_no_name
)
level_path
=
os
.
path
.
join
(
level_no_dir
,
'config.json'
)
level_path
=
os
.
path
.
join
(
level_no_dir
,
'config.json'
)
level_cfg
=
load_json
(
level_path
)
level_cfg
=
ensure_config
(
level_no_dir
)
if
ensure_node_id
(
level_cfg
)
or
check_export
(
level_no_dir
,
level_cfg
):
if
ensure_node_id
(
level_cfg
)
or
check_export
(
level_no_dir
,
level_cfg
):
dump_json
(
level_path
,
level_cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
level_path
,
level_cfg
,
exist_ok
=
True
,
override
=
True
)
if
ensure_title
(
level_cfg
,
level_path
):
if
ensure_title
(
level_cfg
,
level_path
):
...
@@ -148,11 +162,11 @@ def gen_tree(data_path):
...
@@ -148,11 +162,11 @@ def gen_tree(data_path):
for
chapter_no_dir
,
chapter_no_name
in
list_dir
(
level_no_dir
):
for
chapter_no_dir
,
chapter_no_name
in
list_dir
(
level_no_dir
):
no
,
chapter_name
=
parse_no_name
(
chapter_no_name
)
no
,
chapter_name
=
parse_no_name
(
chapter_no_name
)
chapter_path
=
os
.
path
.
join
(
chapter_no_dir
,
'config.json'
)
chapter_path
=
os
.
path
.
join
(
chapter_no_dir
,
'config.json'
)
chapter_cfg
=
load_json
(
chapter_path
)
chapter_cfg
=
ensure_config
(
chapter_no_dir
)
if
ensure_node_id
(
chapter_cfg
)
or
check_export
(
chapter_no_dir
,
chapter_cfg
):
if
ensure_node_id
(
chapter_cfg
)
or
check_export
(
chapter_no_dir
,
chapter_cfg
):
dump_json
(
chapter_path
,
chapter_cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
chapter_path
,
chapter_cfg
,
exist_ok
=
True
,
override
=
True
)
if
ensure_title
(
chapter_cfg
,
chapter_path
):
if
ensure_title
(
chapter_cfg
,
chapter_path
):
dump_json
(
chapter_path
,
chapter_cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
chapter_path
,
chapter_cfg
,
exist_ok
=
True
,
override
=
True
)
chapter_node
,
chapter_node_children
=
make_node
(
chapter_node
,
chapter_node_children
=
make_node
(
chapter_name
,
chapter_cfg
[
'node_id'
],
chapter_cfg
[
'keywords'
])
chapter_name
,
chapter_cfg
[
'node_id'
],
chapter_cfg
[
'keywords'
])
...
@@ -162,7 +176,7 @@ def gen_tree(data_path):
...
@@ -162,7 +176,7 @@ def gen_tree(data_path):
for
section_no_dir
,
section_no_name
in
list_dir
(
chapter_no_dir
):
for
section_no_dir
,
section_no_name
in
list_dir
(
chapter_no_dir
):
no
,
section_name
=
parse_no_name
(
section_no_name
)
no
,
section_name
=
parse_no_name
(
section_no_name
)
sec_path
=
os
.
path
.
join
(
section_no_dir
,
'config.json'
)
sec_path
=
os
.
path
.
join
(
section_no_dir
,
'config.json'
)
sec_cfg
=
load_json
(
sec_path
)
sec_cfg
=
ensure_config
(
section_no_dir
)
flag
=
ensure_node_id
(
sec_cfg
)
or
check_export
(
section_no_dir
,
sec_cfg
)
flag
=
ensure_node_id
(
sec_cfg
)
or
check_export
(
section_no_dir
,
sec_cfg
)
section_node
,
section_node_children
=
make_node
(
section_node
,
section_node_children
=
make_node
(
...
@@ -170,23 +184,23 @@ def gen_tree(data_path):
...
@@ -170,23 +184,23 @@ def gen_tree(data_path):
chapter_node_children
.
append
(
section_node
)
chapter_node_children
.
append
(
section_node
)
# 确保习题分配了习题ID
# 确保习题分配了习题ID
for
export
in
sec_cfg
.
get
(
"export"
,
[]):
for
export
in
sec_cfg
.
get
(
"export"
,
[]):
ecfg_path
=
os
.
path
.
join
(
section_no_dir
,
export
)
ecfg_path
=
os
.
path
.
join
(
section_no_dir
,
export
)
ecfg
=
load_json
(
ecfg_path
)
ecfg
=
load_json
(
ecfg_path
)
if
(
ecfg
.
get
(
'exercise_id'
)
is
None
)
or
(
ecfg
.
get
(
'exercise_id'
)
in
id_set
):
if
(
ecfg
.
get
(
'exercise_id'
)
is
None
)
or
(
ecfg
.
get
(
'exercise_id'
)
in
id_set
):
ecfg
[
'exercise_id'
]
=
uuid
.
uuid4
().
hex
ecfg
[
'exercise_id'
]
=
uuid
.
uuid4
().
hex
dump_json
(
ecfg_path
,
ecfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
ecfg_path
,
ecfg
,
exist_ok
=
True
,
override
=
True
)
id_set
.
add
(
ecfg
[
'exercise_id'
])
id_set
.
add
(
ecfg
[
'exercise_id'
])
if
flag
:
if
flag
:
dump_json
(
sec_path
,
sec_cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
sec_path
,
sec_cfg
,
exist_ok
=
True
,
override
=
True
)
if
ensure_title
(
sec_cfg
,
sec_path
):
if
ensure_title
(
sec_cfg
,
sec_path
):
dump_json
(
sec_path
,
sec_cfg
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
sec_path
,
sec_cfg
,
exist_ok
=
True
,
override
=
True
)
# 保存技能树骨架
# 保存技能树骨架
tree_path
=
os
.
path
.
join
(
data_path
,
'tree.json'
)
tree_path
=
os
.
path
.
join
(
data_path
,
'tree.json'
)
dump_json
(
tree_path
,
root
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
tree_path
,
root
,
exist_ok
=
True
,
override
=
True
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录