In the previous article, we introduced our storage and indexing process, which will introduce SQL queries, single table queries, and TOPN implementations.
One, SQL parsing
Formal SQL parsing is using a parser, but I looked for a long time, only know can use YACC, bison and so on, sqlite use of lemon, pounded the whole day did not implement, the use of the regular expression of Python.
1, delete useless s
I. Installation of XLRD
Address
After downloading, use the pip install .whl installation is good.
View Help:
>>> Import xlrd >>> Help (XLRD) to package Xlrd:name xlrd package CONTENTS BIFFH Book Comp Doc formatting Formula info licences sheet TimeMachine xldate xlsx functions count_records (filename, OUTFILE=L T;idlelib. Pyshell.pseudooutputfile object at 0x0287e730>) dump (filename, outfile=
The above methods allow you to view the XLRD Help information, which contains some modules i
code can start from the ID, convenient.
Insufficient implementation:
In order to prevent the master-slave delay too high, the use of each delete SLEEP1 seconds, relatively rough, the best way should be periodic scan this copy link, according to the delay to adjust the sleep cycle, anyway, scripted, and then intelligent Point why!
The above is a small series to introduce the Python incremental cycle to delete the MySQL
[Spark] [Hive] [Python] [SQL] A small example of Spark reading a hive table$ cat Customers.txt1Alius2Bsbca3Carlsmx$ hiveHive>> CREATE TABLE IF not EXISTS customers (> cust_id String,> Name string,> Country String>)> ROW FORMAT delimited fields TERMINATED by ' \ t ';hive> Load Data local inpath '/home/training/customers.txt ' into
Tags: fetchall nbsp python class set for SEL statement RAM (Create connection and cursor code omitted here) SQL1="SELECT * FROM table name" #SQL statement 1Cursor1.execute (SQL1)#Execute SQL statement 1Read1=list (Cursor1.fetchall ())#reading Results 1Sql2="SHOW full COLUMNS from table name" #SQL Statement 2Cursor1.execute (SQL2)#Execute SQL stat
Because the unit designs the database tables, all use SQL. I don't know what the reason is not to powerdesign or Ermaster tools, to build a table is painful as a program ape of course to find a solution, write a program with Python to solveNeed to use XLRD Linux under sudo pip install xlrdMainly applicable to DB2 databaseThe Excel table structure where number is
XLRD objects to XLWT objects using the Copy method provided by XlutilsTable = Excel.get_sheet (0)#get the sheet you want to manipulate by using the Xlwt object method ifrows = =0: forY, ValueinchEnumerate (First_row): Table.write (rows, y, Value.decode ('Utf-8'), Header_style) Excel.save (file_path)Else: forY, ValueinchEnumerate (my_list): Table.write (rows, y, Value.decode ('Utf-8')) Excel.save (File_path)exceptException, E:PrintePrint "Please close Grade.xls first"if __name
Two-tier data nesting
#!/usr/bin/python
#-*-coding:utf-8-*-"" "
print (9 9) --> multiplication Table
"
"for X in range (1,10):
print with
K in range (1,x+1): # does not miss the range function
print '%d *%d =%s '% (x,k , str (x*k). Ljust (3)), # If don't want to line feed, need the ' comma at the end of the line ' "
How to fill the two-digit local data with two Bit..
1 * 1 = 1
2 * 1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.