??Pythonд???NoSQL?????
???????????? ???????[ 2017/5/24 10:24:14 ] ????????Python ????? NoSQL
????NoSQL ????????Щ????????洦???. ??????? "NoSQL" ???????? ??????β?????????????? ?????? ???????????? Python (????????????? "???????α????") д??? NoSQL ????????????Щ????.
????OldSQL
???????????£? SQL ?????? "?????" (database) ?????????. ?????? SQL ?? Strctured Query Language ?????????д?? ??????????????????. ????е???? ?????????? RDBMS (????????????????? Relational Database Management System ) ?м???????????????. MySQL?? MS SQL Server ?? Oracle ?????? RDBMS ????????.
????RDBMS ?е? R?? ?? "Relational" (?й??????????)?? ????????????????. ??????? ?? (table) ????????? ????????Щ?? ???? (type) ??????? ?? (column) ????. ???б?? ?м???????????????????? schema (???????). schema ???????????????????????????????. ???磬 ?????? Car ?????????????Щ??:
????· Make: a string
????· Model: a string
????· Year: a four-digit number; alternatively?? a date
????· Color: a string
????· VIN(Vehicle Identification Number): a string
???????????У? ???????????????? ?? (row)?? ??????? ??? (record). ??????????????? ?????????? ???? (primary key). ???е? ???? ????????? ?? ????????????. ??? Car ?У? VIN ????????????????? ???????????????????е???. ??????????п?????? Make?? Model?? Year ?? Color ?????????????? ????????????????? ??????в???? VIN. ????? ????????????? VIN?? ????????????????п????????????????????????.
????Querying
????SQL ?????????????????????? query (???) ?????????????. ??? ??????? ???????????????????? RDBMS ????? ??????????н??????????. ????????????????????е???????? ????? ???е? ????? ?????????????????????????μ? SQL ??? :
????SELECT Make?? Model FROM Car;
?????? SQL ???·????????:
????· "SELECT": "??????"
????· "Make?? Model": "Make ?? Model ???"
????· "FROM Car": "??? Car ?е?????"
???????? "???????? Car ?????? Make ?? Model ???". ??в???? ??????????Щ????????? ??????????? Make ?? Model. ?????????????? 1994 ?????????????? ???????:
????SELECT Color FROM Car WHERE Year = 1994;
????????? ?????????????????μ??б?:
????Black
????Red
????Red
????White
????Blue
????Black
????White
????Yellow
?????? ??????????????? (primary key) ???? ?? ?????? VIN ?????????????:
????SELECT * FROM Car WHERE VIN = '2134AFGER245267'
???????????????????????????????????????.
????????????????????????. ?????? ????????? VIN ???????????????????????. ???????????????? ???????????:
????Relations
?????????????????????????????????. ?????????Щ????????飬 ?????????????????????????? ??????????????е????????. ??????????????????????Щ?е? ServiceHistory ??:
????VIN | Make | Model | Year | Color | Service Performed | Mechanic | Price | Date
?????????? ??ε??????????? ?????????????μ???У? ??д???η????????????Щ?????飬 ????λ?????? ???????????????.
???????????£? ????????????????????????????г???????????й??????????? ?????????????? Black 2014 Lexus RX 350 ???? 10 ?ε???? ?????? Make?? Model?? Year ?? Color ??Щ????????????????????????????Щ???. ????Ч???????????? ?????????????????????????洢??Σ? ????????????????в????
????????????????? ????????????????? Vehicle ?? ?????????Щ??:
????VIN | Make | Model | Year | Color
????????????? ???? ServiceHistory ??? ????????????????Щ??:
????VIN | Service Performed | Mechanic | Price | Date
???????????????? VIN ?????????????????? ????????????????????????? ServiceHistory ??? ?? ????????? Vehicle ???е? ?? ?????? ???????????????е????????????????????????? ?????????????????????????????????洢??μ???. ??ε???????????????? ?????? ServiceHistory ???д????μ???У? ???????? Vehicle ????????μ????? ????? ?????????????????
?????????????? SQL ??????????? Vehicle ?? ServiceHistory ??????а???????????:
????SELECT Vehicle.Model?? Vehicle.Year FROM Vehicle?? ServiceHistory WHERE Vehicle.VIN = ServiceHistory.VIN AND ServiceHistory.Price > 75.00;
?????ò????????????????? $75.00 ?????г????? Model ?? Year. ??????????????? Vehicle ?? ServiceHistory ???е? VIN ?????????????????. ??????????????з??????????Щ????? ?? "Vehicle.Model" ?? "Vehicle.Year" ?? ??????????? Vehicle ???е???????.
???????????????????? ???? (indexes) (?????????? indices)?? ????????????? ????? (table scan) ????λ??????????С? table scan ???????????е????н??????μ?飬 ????????????????? ?????? table scan ??????????в?????????
??????????????м???????????????? ?????????????????????????? ???????????????????????????????????????????????? (???????Χ????Щ?). ?????? ????????? Price ??????????????? ?????????????е?????????????????ж??????????? 75.00?? ??????????e??????????е???? “??” ????????????? 75.00 ??????У? ??????????????(???????????????? ?????Щ?е????????? 75.00)??
????????????????????? ?????????????????????????????????? ?????е???????????е??????? ????????????Щ?????????? ???????????????????棬????Щ??汾????????????д洢?????????????????????????????????е???? ???????????????м??????? ??? ????????????
????The Clear Box
?????????????????????????? schema (????????а????????????????)?? ?????????????????????????? ??????????????????????????????? ?????? ???????????????? ???????????? “???” (?????????????) ???????
????????????? NoSQL ?????????????μ??????? ???漰 query ???????????????????????? ????????з?????????????
????Schemas
???????????????? ????? schema ?? ???????е???????????????????????????????????????Щ????? ??????Щ?п??????? ??Щ?в????????????? ?????????????е?????????????? ????????????????????? schema?? ???? ???е??????б??????? schema ??漲 ??
???????????????????????????? ??????????????????? ?????????????????????????? ?????????????????????Щ??? (???磬 ?????????)?? ?????????????????????????? ??????? alter (????) ???е?? -- ????μ???С? ?????????????????е????ж??????б??????????? ???????£? ????????????????е????? ?????????????????????Щ?????????????????(???????????????????????)???????????????????????Щ???????
?????????????????????????Щ???????????????С???????????????????????????????????????????????????? schema ??????????????????????????????Щ???? schema ??????????? DBA ??????????????????
????Key/Value Stores
?????? “NoSQL” ??????????? ?? memcached ?????? ??/? ????洢 (Key/Value Data Stores) ???? table schema ?????????洢?????? ?????? ?? K/V ?洢??? ??????? "?? (table)" ???? ??? ?? (keys) ?? ? (values) . ???????洢????????????????? ?????????????????????????? Python ?? dict ?? set ?????: ??? hash table (?????) ?????????????????????? ??????? Python ?????? NoSQL ????? ???????????????? (dictionary) .
????????????????????????????д?????! ????????????Щ???????????
????· ??? Python ?? dict ????????????洢
????· ????? string ????????? (key)
????· ???洢 integer?? string ?? list
????· ?????? ASCLL string ??? TCP/IP ?????????????????
????· ?Щ?? INCREMENT?? DELETE ?? APPEND ?? STATS ???????????? (command)
????????????? ASCII ?? TCP/IP ????????洢?????????? ??????????ü??? telnet ????????????????н????? ???????????????? (???????????????????????????? 15 ?д????????)??
???????????????????????????????????????????????? “??????”????????????????????
????Commands Supported
????PUT
?????????? Key?? Value
???????? ????????в???????μ???? (entry)
????GET
?????????? Key
???????? ????????м????????洢???
????PUTLIST
?????????? Key?? Value
???????? ????????в???????μ??б????
????APPEND
?????????? Key?? Value
???????? ???????????????е??б????????μ????
????INCREMENT
?????????? key
???????? ????????????????????
????DELETE
?????????? Key
???????? ??????????????????
????STATS
?????????? ?? (N/A)
???????? ??????????????? ???/??? ????????
??????????????????????????????
????Message Structure
????Request Messages
??????? ??????? (Request Message) ?????????????(command)??????? (key)?? ???? (value)?? ??????????(type). ????????????????????????? ?????; ????????????????????а???????????? ???????????????????????? ; ?????
????COMMAND; [KEY]; [VALUE]; [VALUE TYPE]
????· COMMAND ???????б??е???????
????· KEY ?????????????????? key ?? string (???)
????· VALUE ????????е???? integer?? list ?? string (???)
????· list ??????????????????????? string?? ??????? "red?? green?? blue"
????· VALUE TYPE ?????? VALUE ???????????????
???????????????У?INT?? STRING?? LIST
????· Examples
????· "PUT; foo; 1; INT"
????· "GET; foo;;"
????· "PUTLIST; bar; a??b??c ; LIST"
????· "APPEND; bar; d; STRING"
????· "GETLIST; bar; ;"
????· STATS; ;;
????· INCREMENT; foo;;
????· DELETE; foo;;
????· Reponse Messages
??????? ?????? (Reponse Message) ??????????????? ??? ; ???з???????????????? True|False ?? ???????????е???????????? ?????????????????? (command message)?? ?????????????????????????????????Щ??г???????????????????????????(???? PUT)?? ?????????????? ?????????????????? (???? GET)?? ??????????????????????
????Examples
????· True; Key [foo] set to [1]
????· True; 1
????· True; Key [bar] set to [['a'?? 'b'?? 'c']]
????· True; Key [bar] had value [d] appended
????· True; ['a'?? 'b'?? 'c'?? 'd']
????· True; {'PUTLIST': {'success': 1?? 'error': 0}?? 'STATS': {'success': 0?? 'error': 0}?? 'INCREMENT': {'success': 0?? 'error': 0}?? 'GET': {'success': 0?? 'error': 0}?? 'PUT': {'success': 0?? 'error': 0}?? 'GETLIST': {'success': 1?? 'error': 0}?? 'APPEND': {'success': 1?? 'error': 0}?? 'DELETE': {'success': 0?? 'error': 0}}
????Show Me The Code!
??????????????????????????????? ?????????? 180 ?У???????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11