欢迎光临散文网 会员登陆 & 注册

hadoop

2023-06-14 14:41 作者:闭关修炼的庸人  | 我要投稿

 1.Hive分区创建表

Hive>create  table t_user_p(id int, name string)

Partitioned by (country string)

Row format delimited fields terminated by ‘,’;

2.mongoDB数据库集合,文档,查询

(1)查看集合

from pymongo import MongoClient

class Test:

       def _ _init _ _(self):

           self.client=MongoClient(’192.168.121.134’,27017)

        def getColl(self):

             articledb = self.client[”articledb”]

             collections=articledb.list_collection_names()

             for collection in collections:

                    print(collection)

if _ _name _ _ ==’_ _main_ _’:

          test = Test()

           test.getColl()

(2)创建集合

from pymongo import MongoClient

class Test:

       def _ _init _ _(self):

           self.client=MongoClient(’192.168.121.134’,27017)

       def createColl(self):

             articledb = self.client[”articledb”]

             articledb.create_collection(”itcast”)

  if _ _name _ _ ==’_ _main_ _’:

        test = Test()

        test.createColl()

(3)删除集合

from pymongo import MongoClient

class Test:

       def _ _init _ _(self):

           self.client=MongoClient(’192.168.121.134’,27017)

       def dropColl(self):

            articledb = self.client[”articledb”]

             articledb.drop_collection(”itcast”)

  if _ _name _ _ ==’_ _main_ _’:

        test = Test()

        test.dropColl()

(3)查看文档

from pymongo import MongoClient

class Test:

       def _ _init _ _(self):

           self.client=MongoClient(’192.168.121.134’,27017)

       def findDoc(self):

            self.articledb = self.client[”articledb”]

            comment = self.articledb[”comment”]

           documents = comment.find()

                          for  document in documents:

                   print( document)

  if _ _name _ _ ==’_ _main_ _’:

        test = Test()

        test.findDocl()

 


hadoop的评论 (共 条)

分享到微博请遵守国家法律