当前位置: 首页>>代码示例>>Python>>正文


Python csvsql.CSVSQL类代码示例

本文整理汇总了Python中csvkit.utilities.csvsql.CSVSQL的典型用法代码示例。如果您正苦于以下问题:Python CSVSQL类的具体用法?Python CSVSQL怎么用?Python CSVSQL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CSVSQL类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: csvsql

    def csvsql(self, csv_file):
        """
        Load test data into the DB and return it as a string for comparison.
        """
        args = ["--db", "sqlite:///" + self.db_file, "--table", "foo", "--insert", csv_file]

        utility = CSVSQL(args)
        utility.main()

        return open(csv_file, "r").read().strip()
开发者ID:pombredanne,项目名称:csvkit,代码行数:10,代码来源:test_sql2csv.py

示例2: test_empty_with_query

    def test_empty_with_query(self):
        input_file = six.StringIO()

        with stdin_as_string(input_file):
            output_file = six.StringIO()
            utility = CSVSQL(['--query', 'select 1'], output_file)
            utility.run()
            output_file.close()

        input_file.close()
开发者ID:skorasaurus,项目名称:csvkit,代码行数:10,代码来源:test_csvsql.py

示例3: getHiveSQL

def getHiveSQL(args):
#args = ['--table', 'customer', '/home/ranjan/reb_repository/customer.csv']
	output_file = six.StringIO()
	utility = CSVSQL(args, output_file)
	utility.main()
	sql = output_file.getvalue()

	dropsql = "DROP TABLE IF EXISTS %s" % (args[1])
	createsql =  sql[:-2] + " row format delimited fields terminated by ','"
	loadsql = "LOAD DATA LOCAL INPATH '/repository/%s.csv' OVERWRITE INTO TABLE %s" % (args[1],args[1])

	#print dropsql
	#print createsql
	#print loadsql

	extn_fields = createsql[ createsql.index("(")+1: createsql.index(") row") ]
	#print extn_fields

	hdp_extn_sql = """

drop server if exists fdw_hadoop_srv cascade;
create server fdw_hadoop_srv foreign data wrapper multicorn	
options(
	wrapper 'reb_main.HadoopFDW'
);

drop foreign table if exists fdw_hdp_%s cascade;

create foreign table fdw_hdp_%s (
	%s
	
)server fdw_hadoop_srv options(
	createsql '%s',
	loadsql '%s',
	dropsql '%s',
	selectsql '%s',
	docker_start 'docker run  -d -v /home/ranjan/reb_repository:/repository -p 10000:10000 --name rebdoop rebdoop',
	docker_stop  'docker stop rebdoop',
	docker_remove 'docker rm rebdoop'

);

""" 	% (
		args[1],
		args[1],
		extn_fields,
		createsql.replace("'","''"),
		loadsql.replace("'","''"),
		dropsql.replace("'","''"),
		"select * from %s" % args[1] 		
	)

	print hdp_extn_sql
	return [loadsql,createsql,dropsql]
开发者ID:decibel,项目名称:rebataur,代码行数:54,代码来源:hdp_cons.py

示例4: test_no_header_row

    def test_no_header_row(self):
        args = ['--table', 'foo', '--no-header-row', 'examples/no_header_row.csv']
        output_file = six.StringIO()

        utility = CSVSQL(args, output_file)
        utility.main()

        sql = output_file.getvalue()

        self.assertTrue('CREATE TABLE foo' in sql)
        self.assertTrue('column1 INTEGER NOT NULL' in sql)
        self.assertTrue('column2 INTEGER NOT NULL' in sql)
        self.assertTrue('column3 INTEGER NOT NULL' in sql)
开发者ID:haginara,项目名称:csvkit,代码行数:13,代码来源:test_csvsql.py

示例5: test_stdin_and_filename

    def test_stdin_and_filename(self):
        args = ['examples/dummy.csv']
        output_file = six.StringIO()

        input_file = six.StringIO("a,b,c\n1,2,3\n")

        with stdin_as_string(input_file):
            utility = CSVSQL(args, output_file)
            utility.main()

            sql = output_file.getvalue()

            self.assertTrue('CREATE TABLE stdin' in sql)
            self.assertTrue('CREATE TABLE dummy' in sql)
开发者ID:haginara,项目名称:csvkit,代码行数:14,代码来源:test_csvsql.py

示例6: test_stdin

    def test_stdin(self):
        args = ['--table', 'foo']
        output_file = six.StringIO()

        input_file = six.StringIO('a,b,c\n1,2,3\n')

        with stdin_as_string(input_file):
            utility = CSVSQL(args, output_file)
            utility.main()

            sql = output_file.getvalue()

            self.assertTrue('CREATE TABLE foo' in sql)
            self.assertTrue('a INTEGER NOT NULL' in sql)
            self.assertTrue('b INTEGER NOT NULL' in sql)
            self.assertTrue('c INTEGER NOT NULL' in sql)
开发者ID:haginara,项目名称:csvkit,代码行数:16,代码来源:test_csvsql.py

示例7: test_no_inference

    def test_no_inference(self):
        args = ['--table', 'foo', '--no-inference', 'examples/testfixed_converted.csv']
        output_file = six.StringIO()

        utility = CSVSQL(args, output_file)
        utility.main()

        sql =  output_file.getvalue()

        self.assertTrue('CREATE TABLE foo' in sql)
        self.assertTrue('text VARCHAR(17) NOT NULL' in sql)
        self.assertTrue('date VARCHAR(10) NOT NULL' in sql)
        self.assertTrue('integer VARCHAR(3) NOT NULL' in sql)
        self.assertTrue('boolean VARCHAR(5) NOT NULL' in sql)
        self.assertTrue('float VARCHAR(11) NOT NULL' in sql)
        self.assertTrue('time VARCHAR(8) NOT NULL' in sql)
        self.assertTrue('datetime VARCHAR(19) NOT NULL' in sql)
开发者ID:haginara,项目名称:csvkit,代码行数:17,代码来源:test_csvsql.py

示例8: test_create_table

    def test_create_table(self):
        args = ['--table', 'foo', 'examples/testfixed_converted.csv']
        output_file = six.StringIO()

        utility = CSVSQL(args, output_file)
        utility.main()

        sql = output_file.getvalue()

        self.assertTrue('CREATE TABLE foo' in sql)
        self.assertTrue('text VARCHAR(17) NOT NULL' in sql)
        self.assertTrue('date DATE' in sql)
        self.assertTrue('integer INTEGER' in sql)
        self.assertTrue('boolean BOOLEAN' in sql)
        self.assertTrue('float FLOAT' in sql)
        self.assertTrue('time TIME' in sql)
        self.assertTrue('datetime DATETIME' in sql)
开发者ID:haginara,项目名称:csvkit,代码行数:17,代码来源:test_csvsql.py

示例9: test_query

    def test_query(self):

        args = ['--query', 'select m.usda_id, avg(i.sepal_length) as mean_sepal_length from iris as i join irismeta as m on (i.species = m.species) group by m.species', 'examples/iris.csv', 'examples/irismeta.csv']
        output_file = StringIO()

        input_file = StringIO("a,b,c\n1,2,3\n")

        with stdin_as_string(input_file):
            utility = CSVSQL(args, output_file)
            utility.main()

            sql = output_file.getvalue()

            self.assertTrue('usda_id,mean_sepal_length' in sql)
            self.assertTrue('IRSE,5.006' in sql)
            self.assertTrue('IRVE2,5.936' in sql)
            self.assertTrue('IRVI,6.588' in sql)
开发者ID:GMADIGITAL,项目名称:csvkit,代码行数:17,代码来源:test_csvsql.py

示例10: test_empty_with_query

 def test_empty_with_query(self):
     with stdin_as_string(six.StringIO()):
         utility = CSVSQL(['--query', 'select 1'], six.StringIO())
         utility.main()
开发者ID:andrewluetgers,项目名称:csvkit,代码行数:4,代码来源:test_csvsql.py


注:本文中的csvkit.utilities.csvsql.CSVSQL类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。