473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Table Oriented Programming

Yeah, yeah, another X-Oriented paradigm, but please hear me out.

I have recently been studying up on EJB's in order to extend my resume.
I have looked at J2EE several times over the past years, but have never
been impressed by it. Now that I've studied it in detail, I know why. A
strongly typed language such as Java is poorly suited to model tables
and relations.

I got to thinking that a more dynamically typed language, such as
Python, would be a more natural fit. I've always been fond of the
table-oriented programming ideas described in
http://www.geocities.com/tablizer/top.htm, so I'm thinking that if
Python could be extended to handle table-oriented programming as
seamlessly as it handles object-oriented programming, it could become a
really valuable language for writing enterprise components, a la EJB.

Does anyone know if anyone has already walked this path?

I've given it a little thought myself, and here are some of my
[incomplete] ideas:

- Tables would be first-class values, just as classes are.
- A table may be stored completely in memory, or it may represent a
table stored in a database engine.
- A table may represent the result of a query.
- Queries are performed using a sequence of operators, rather than
relying on SQL.

Consider this example code:
departments = DepartmentTable
employees = EmployeeTable
johnsDepartment = (departments * employees) /
(employees.dept == departments.dept) /
(employees.name == 'John') %
departments.name
print johnsDepartment[0].name

In the code above, the "*" operator performs a cartesian product, the
"/" operator performs a selection, and the "%" operator performs a
projection. If the DepartmentTable and the EmployeeTable are stored in a
database engine, the expression above would generate a SQL query similar
to "select department.name from (select * from department, employee
where employee.dept = department.dept) where employee.name = 'John'". If
the expression had been written "(departments * employees) /
(employees.dept == departments.dept and employees.name == 'John') %
departments.name", the resulting SQL would be similar to "select
department.name from department, employee where employee.dept =
department.dept and employee.name = 'John'", that is, without the nested
SELECT.

Of course, the entire code above could be reduced to a single line:
print ((DepartmentTable * EmployeeTable) / (EmployeeTable.dept ==
DepartmentTable.dept and EmployeeTable.name == 'John') %
DepartmentTable.name)[0].name

Perhaps the list-comprehension syntax may be better suited than
arithmetic operators. Like I said, my ideas are still a little
incomplete.

Please forgive me if this has already been discussed to death,
- Michael Hobbs

Jul 18 '05 #1
5 2355

"Michael Hobbs" <mi*****@hobbshouse.org> wrote in message
news:ma************************************@python .org...
Yeah, yeah, another X-Oriented paradigm, but please hear me out.

I have recently been studying up on EJB's in order to extend my resume.
I have looked at J2EE several times over the past years, but have never
been impressed by it. Now that I've studied it in detail, I know why. A
strongly typed language such as Java is poorly suited to model tables
and relations.

I got to thinking that a more dynamically typed language, such as
Python, would be a more natural fit. I've always been fond of the
table-oriented programming ideas described in
http://www.geocities.com/tablizer/top.htm, so I'm thinking that if
Python could be extended to handle table-oriented programming as
seamlessly as it handles object-oriented programming, it could become a
really valuable language for writing enterprise components, a la EJB.

Does anyone know if anyone has already walked this path?

I've given it a little thought myself, and here are some of my
[incomplete] ideas:

- Tables would be first-class values, just as classes are.
- A table may be stored completely in memory, or it may represent a
table stored in a database engine.
- A table may represent the result of a query.
- Queries are performed using a sequence of operators, rather than
relying on SQL.

Consider this example code:
departments = DepartmentTable
employees = EmployeeTable
johnsDepartment = (departments * employees) /
(employees.dept == departments.dept) /
(employees.name == 'John') %
departments.name
print johnsDepartment[0].name

In the code above, the "*" operator performs a cartesian product, the
"/" operator performs a selection, and the "%" operator performs a
projection. If the DepartmentTable and the EmployeeTable are stored in a
database engine, the expression above would generate a SQL query similar
to "select department.name from (select * from department, employee
where employee.dept = department.dept) where employee.name = 'John'". If
the expression had been written "(departments * employees) /
(employees.dept == departments.dept and employees.name == 'John') %
departments.name", the resulting SQL would be similar to "select
department.name from department, employee where employee.dept =
department.dept and employee.name = 'John'", that is, without the nested
SELECT.

Of course, the entire code above could be reduced to a single line:
print ((DepartmentTable * EmployeeTable) / (EmployeeTable.dept ==
DepartmentTable.dept and EmployeeTable.name == 'John') %
DepartmentTable.name)[0].name

Perhaps the list-comprehension syntax may be better suited than
arithmetic operators. Like I said, my ideas are still a little
incomplete.

Please forgive me if this has already been discussed to death,
- Michael Hobbs


It's an intriguing idea; I've had the occasional thought of
wanting an in-memory relational algebra implementation (which
is what he's actually specifying once you get him down off of
the hobby-horse he's riding.)

Put together a package and see whether it flies for real world
problems. That's the usual path for inclusion into Python - put a
pure Python package together, see if you can get people excited
about actually using it, and then propose it for inclusion into the
standard library.

John Roth
Jul 18 '05 #2
In article <10*************@news.supernews.com>,
John Roth <ne********@jhrothjr.com> wrote:
Jul 18 '05 #3
"Michael Hobbs" <mi*****@hobbshouse.org> wrote in message news:<ma************************************@pytho n.org>...
Yeah, yeah, another X-Oriented paradigm, but please hear me out.

I have recently been studying up on EJB's in order to extend my resume.
I have looked at J2EE several times over the past years, but have never
been impressed by it. Now that I've studied it in detail, I know why. A
strongly typed language such as Java is poorly suited to model tables
and relations.

I got to thinking that a more dynamically typed language, such as
Python, would be a more natural fit. I've always been fond of the
table-oriented programming ideas described in
http://www.geocities.com/tablizer/top.htm, so I'm thinking that if
Python could be extended to handle table-oriented programming as
seamlessly as it handles object-oriented programming, it could become a
really valuable language for writing enterprise components, a la EJB.

Does anyone know if anyone has already walked this path?

I've given it a little thought myself, and here are some of my
[incomplete] ideas:

- Tables would be first-class values, just as classes are.
- A table may be stored completely in memory, or it may represent a
table stored in a database engine.
- A table may represent the result of a query.
- Queries are performed using a sequence of operators, rather than
relying on SQL.

Consider this example code:
departments = DepartmentTable
employees = EmployeeTable
johnsDepartment = (departments * employees) /
(employees.dept == departments.dept) /
(employees.name == 'John') %
departments.name
print johnsDepartment[0].name

In the code above, the "*" operator performs a cartesian product, the
"/" operator performs a selection, and the "%" operator performs a
projection. If the DepartmentTable and the EmployeeTable are stored in a
database engine, the expression above would generate a SQL query similar
to "select department.name from (select * from department, employee
where employee.dept = department.dept) where employee.name = 'John'". If
the expression had been written "(departments * employees) /
(employees.dept == departments.dept and employees.name == 'John') %
departments.name", the resulting SQL would be similar to "select
department.name from department, employee where employee.dept =
department.dept and employee.name = 'John'", that is, without the nested
SELECT.

Of course, the entire code above could be reduced to a single line:
print ((DepartmentTable * EmployeeTable) / (EmployeeTable.dept ==
DepartmentTable.dept and EmployeeTable.name == 'John') %
DepartmentTable.name)[0].name

Perhaps the list-comprehension syntax may be better suited than
arithmetic operators. Like I said, my ideas are still a little
incomplete.

Please forgive me if this has already been discussed to death,
- Michael Hobbs


What about the following code ?
I think there is not too much to make it work...
"""
http://www.geocities.com/tablizer/top.htm
http://groups.google.fr/groups?q=Tab...hon.org&rnum=1
"""
class TOP(object):
def __div__(self,other):
return Selection(self,other)

def __mul__(self,other):
return CartesianProduct(self,other)

def __eq__(self,other):
return Equality(self,other)

def __mod__(self,other):
return Projection(self,other)

def execute(self,connexion):
self._cursor = connexion.cursor()
self._cursor.execute(ToSql().toSql(self))

def __getitem__(self,item):
if not hasattr(self,'_result'):
self._result = self._cursor.fetchall()
return self._result[item]

def __iter__(self):
return self._iter

def _iter(self):
set = self._cursor.nextset()
while set:
yield set
set = self._cursor.nextset()
class Table(TOP):
def __init__(self,name):
self._name = name

def __getattr__(self,attr):
return Field(self,attr)

def __str__(self):
return self._name

class Field(TOP):
def __init__(self,table,fieldName):
self._table = table
self._name = fieldName

def __str__(self):
return "%s.%s" % (self._table,self._name)

class Equality(TOP):
def __init__(self,a,b):
self.a = a
self.b = b

class Selection(TOP):
def __init__(self,a,b):
self.a = a
self.b = b

class CartesianProduct(TOP):
def __init__(self,a,b):
self.a = a
self.b = b

class Projection(TOP):
def __init__(self,a,b):
self.a = a
self.b = b
class ToSql:
def __init__(self):
pass

def toSql(self,obj):
methodName = "toSql" + obj.__class__.__name__
if hasattr(self,methodName):
toSql = getattr(self,methodName)
return toSql(obj)
else:
#print methodName
return '"%s"' % str(obj)

def toSqltuple(self,tuple):
return ",".join(map(lambda o: self.toSql(o),tuple))

def toSqlTable(self,table):
return str(table)

def toSqlField(self,field):
return str(field)

def toSqlCartesianProduct(self,prod):
return "%s,%s" % (self.toSql(prod.a),self.toSql(prod.b))

def toSqlEquality(self,eq):
return "%s == %s" % (self.toSql(eq.a),self.toSql(eq.b))

def toSqlSelection(self,sel):
if isinstance(sel.a,Selection):
return "%s AND %s" % (self.toSql(sel.a),self.toSql(sel.b))
else:
return "%s WHERE %s" %
(self.toSql(sel.a),self.toSql(sel.b))

def toSqlProjection(self,proj):
if isinstance(proj.a,Projection):
return "?"
else:
return "SELECT %s FROM %s" % (self.toSql(proj.b),
self.toSql(proj.a))

translator = ToSql()

departments = Table("DepartmentTable")
employees = Table("EmployeeTable")

johnsDepartment = ( departments * employees) / (employees.dept ==
departments.dept) / ( employees.name == "John") % departments.name
johnsDepartmentBis = ( departments * employees) / (employees.dept ==
departments.dept) / ( employees.name == "John") %
(departments.name,employees.surname)

print translator.toSql(johnsDepartment)
print translator.toSql(johnsDepartmentBis)

##johnsDepartment.execute(myBddConnexion)
##print johnsDepartment[0]

##johnsDepartmentBis.execute(myBddConnexion)
##for item in johnsDepartmentBis:
## print item
Jul 18 '05 #4

"Cameron Laird" <cl****@lairds.com> wrote in message
news:10*************@corp.supernews.com...
In article <10*************@news.supernews.com>,
John Roth <ne********@jhrothjr.com> wrote:
.
.
.
It's an intriguing idea; I've had the occasional thought of
wanting an in-memory relational algebra implementation (which
is what he's actually specifying once you get him down off of
the hobby-horse he's riding.)

Put together a package and see whether it flies for real world
problems. That's the usual path for inclusion into Python - put a
pure Python package together, see if you can get people excited
about actually using it, and then propose it for inclusion into the
standard library.

John Roth
Notable contributor Jean-Claude Wippler is just now releasing some
<URL: http://www.equi4.com/pipermail/stark...ry/001829.html >
of his implementations in the area of relational algebra.


It's in TCL. Sigh.

John Roth --

Cameron Laird <cl****@phaseit.net>
Business: http://www.Phaseit.net

Jul 18 '05 #5
John Roth wrote:
Notable contributor Jean-Claude Wippler is just now releasing some
<URL: http://www.equi4.com/pipermail/stark...ry/001829.html >
of his implementations in the area of relational algebra.

It's in TCL. Sigh.


Be assured that Wippler targets every language he can. I can't give too
many details because I promised not to, but python will work on the
finished system and, in fact, will be a first-class language target.
I'm including Jean-Claude in this discussion, btw, incase he wants to
add anything.

Metakit itself is relational algebra based on columns, it just happens
to be more database like. I'm have been using it to perform most of the
rattcl operations mentioned above, I just have a thin wrapper to create
the table structure around metakit. Gordon McMillan even has support to
"wrap" any python sequence as a metakit view and viola - you have all
the relational algebra support you want. Set operations, ordering,
joins, selects, filters... I've been so impressed by the underlying
technology that I'm thinking about writing a small book/tutorial on
metakit-specific relational algebra.

On top of that, Wippler and I have a metakit-server project using the
metakit structure as a wire protocol to send full or partial database
information across a socket. This is language independent so you can
send databases to python/C++/java etc. You can think of it as a sort of
a cross-platform database marshaller. If any one is interested, gunniea
pigs are always welcome.

Metakit is incredibly powerful, by the way. I have successfully used
metakit to form cross-database sql queries using it as the relational
algebra engine to combine SQL queries from Oracle and Mysql for
instance. So if you want to dip your toes in relational algebra, start
playing with metakit, it is way more than a database.

Brian
Whitehead Institute for Biomedical Research

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin | last post by:
When was inheritance intruduced into object oriented programming? More generally, does anyone know or have any sources on when the different features were introduced into object oriented...
34
by: Pmb | last post by:
Hi. I'm new to this group. I'm refreshing/learning C++ and am starting to learn Object Oriented Programming (OOP). In discussing this with people I came up short as to what the benefits of OOP are....
4
by: mihai | last post by:
I wander what is the penalty of speend for using object oriented programming (C++) against the play C. Have a nice day, Mihai
7
by: Wolfgang Kreuzer | last post by:
Hello all, I have two tables - Projects and ProjectStruct Table Projects contains master records of the projects, ProjectStruct allows to define a project herarchie and contains the fields...
14
by: Rookie | last post by:
Is C an object oriented programming language?
8
by: Dale | last post by:
I've searched Amazon and read probably 100 reviews but can't find what seems to be any book that is widely accepted as the definitive book on object oriented programming design and techniques. And...
3
dmjpro
by: dmjpro | last post by:
plz send me a good link which can clearify me how the J2EE framework works i want the details information .... plz help thanx
46
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented...
3
by: notnorwegian | last post by:
i have some confusion over this. sure a class is basically a classification, like for example an animal or flower. and an object/instance of that class is then for example a cat. an object is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.