Is there a CDS view annotation (ABAP) to remove/select a field? - eclipse

I created an ABAP CDS view from a dataset. This dataset contains data with a field "OrderID" (from order 1 to order 10000). Based on this field, OrderID, I would like to create 2 query views : one containing only data from order 1 to 20 and another one with order 50 to 70.
Therefore, I was wondering if there is an annotation to select the value I want to show/remove. I don't want to filter for performance reason.

Use a where clause, as described in the ABAP keyword documentation:
define view first_query_view as
select from your_base_view
{ ... }
where OrderID between 1 and 20;
define view second_query_view as
select from your_base_view
{ ... }
where OrderID between 50 and 70;
Annotations explain how views and the elements in them are to be used. They don't control how the data is retrieved, joined, or filtered.

Related

How do I merge a frequency count back onto a table in postgresql?

I am attempting to count the number of each category and merge it back onto the table by overwriting the table in postgresql.
This is the main table I have (Named Titanic, containing the columns in question):
PassengerId
Group
0001_01
1
0002_01
2
0003_01
3
0003_02
3
I've altered the table by adding a new numeric column "GroupSize" which I want to contain the frequency counts of each group category. So record 1, would be a count of 1, record 2 would be a count of 1 and record 3 and 4 would both be a count of 2. And I want my main "Titanic" table to be retained as opposed to creating a new table or view so ideally using an "Update" statement to impute values into "GroupSize";
I have created a view to contain group the corresponding frequency counts from this code:
CREATE OR REPLACE VIEW "GroupSize"("Group", "GroupSize") AS
select "Group", count("Group") from "Titanic" GROUP BY "Group";
which outputs this:
Group
GroupSize
1
1
2
1
3
2
And I've tried an Update statement to use this view to add data into my "GroupSize" column from "Titanic" like such:
UPDATE "Titanic"
SET "GroupSize" = (SELECT "GroupSize" from "GroupSize")
WHERE "Group" IN (SELECT "Group" from "GroupSize");
I have been unsuccessful in getting this UPDATE statement to work mainly because I get an error: "more than one row returned by a subquery used as an expression". I am pretty new to SQL so ny help would be appreciated.
You almost had it right. The value used in SET is dynamic based off the row being modified. All you have to do is add a WHERE clause to it to ensure it picks the right value from the view.
UPDATE "Titanic"
SET "GroupSize" = (
SELECT "GroupSize" from "GroupSize"
where "Titanic"."Group" = "GroupSize"."Group"
-- (Pedantic safety limit, just in case)
limit 1
)
Beware, though, this will modify every row, setting NULL for values not found in the view. To have it preserve "GroupSize" column for rows without a match in the view, tack on another WHERE clause:
UPDATE "Titanic"
SET "GroupSize" = (
SELECT "GroupSize" from "GroupSize"
where "Titanic"."Group" = "GroupSize"."Group"
limit 1
)
WHERE "Group" IN (SELECT "Group" from "GroupSize");
Do not actually Update you main table, just create the view to hold the group size. This eliminates maintenance headaches when performing DML on the table, image what extra you need to transfer one group to another. With the count only in the view, you do nothing extra. You get the count of id in each group with the window version of count. (see demo)
create or replace view titanic_vw as
select passengerid "Passenger Id"
, passenger_group "Group"
, count(*) over (partition by passenger_group) "Group Size"
from titanic;

Is there a way to work with records that you marked in table on X++?

I want to work with table records that is selected (Marked), Example - I have 10 records in table and i mark 5 of them. Expected - when i work with selected records, it should look only on that 5 records, not whole 10.
So far i have this code that selects all records:
while select Table
where table.JournalId == table.JournalId
Is there a way to make it select only marked records, not everything?
That select is writen in class. I need to get those marked records into that class where that select is writen...
You need to pass the formdatasource object into the class that is selecting the records, and then use the MultiSelectionHelper to loop through the selected records on the formdatasource.
In the example below, the object salesTableFormDataSource needs to be passed in from the form to the class you are using. Obviously replace that with whatever your datasource/table needs are.
MultiSelectionHelper selection = MultiSelectionHelper::construct();
selection.parmDatasource(salesTableFormDataSource);
SalesTable salesTable = selection.getFirst();
while (salesTable)
{
//do something with your table buffer.
salesTable = selection.getNext();
}

softfluent entity related method

I want to get the detail entity of a parent entity with a custom method in this method I want to sort the detail entity random and exclude the details by a condition it's possible in the parent method set the method for get the childs of the parent entity?
In your example I have order and orderdetail like this:
OrderId = 1
date = 2015-06-01
Order detail
Order id = 1
Product = 1
RowNumber = 2
Order detail
Order id = 1
Product = 2
RowNumber = 3
I need that the order details shoul be order by rownumber in a random sort and I want that I get in the order object when I acces to the detail like Order.OrderDetails I get the orderdetails in random I have a method that returns the orderdetail in random but I don't set how set in the graphical design to set my method for get the orderdetails list collection. Other dude I try to add a cfl method for order random something like this in the order detail object
LOAD (int orderId) WHERE orderId = #orderId ORDER BY NEWID()
SELECT * FROM table ORDER BY NEWID()
and get a random order but I get and error so I add a partial class to order by random and add for example an product id like this a)2 b) 1
You can create a CFQL method with inline SQL:
<cf:method name="LoadByOrderRandom"
body="LOAD(Order) where Order = #Order order by [newid()]"
checkLevel="None" />
More information about raw methods: http://blog.codefluententities.com/2014/07/03/cfql-raw-methods/

Use view with Entity framework

I’m developing an application where I’m using Entity Framework. I have a table A and an autogen entity from this table class A
Public Class A
ID As Integer
Sum As Integer
TotalSum As Integer
LastPayment As Integer
NewPayment As Integer
.
.
.
End Class
In addition to my table I have a view that calculates and returns all the rows from table A where totalSum and LastPayment meets some conditions (table has 50 rows, view returns 35 rows).
Can I use this view together with my entity class A? When I use my entity class A I can say
unitOfWork.ARepository.Filter(Function(p) p.ID = Me._id, , )
but this will get the rows from the table without the calculations/filtering done by the view, let say it returns 50 row. I want to say
unitOfWork.ARepository.Filter(Function(p) p.ID = Me._id, , )
but I want to get the filtered rows from the view instead, this will return 35 rows instead of the 50. But I do not want the view to be an entity in my model, because I then will have two classes A (from table) and B (from view) that looks exactly the same. How can I solve this?
you can write a code corresponding view with entity framework in VB or C#. it's better than use 2 model that are equal.

One to Many equivalent in Cassandra and data model optimization

I am modeling my database in Cassandra, coming from RDBMS. I want to know how can I create a one-to-many relationship which is embedded in the same Column Name and model my table to fit the following query needs.
For example:
Boxes:{
23442:{
belongs_to_user: user1,
box_title: 'the box title',
items:{
1: {
name: 'itemname1',
size: 44
},
2: {
name: 'itemname2',
size: 24
}
}
},
{ ... }
}
I read that its preferable to use composite columns instead of super columns, so I need an example of the best way to implement this. My queries are like:
Get items for box by Id
get top 20 boxes with their items (for displaying a range of boxes with their items on the page)
update items size by item id (increment size by a number)
get all boxes by userid (all boxes that belongs to a specific user)
I am expecting lots of writes to change the size of each item in the box. I want to know the best way to implement it without the need to use super columns. Furthermore, I don't mind getting a solution that takes Cassandra 1.2 new features into account, because I will use that in production.
Thanks
This particular model is somewhat challenging, for a number of reasons.
For example, with the box ID as a row key, querying for a range of boxes will require a range query in Cassandra (as opposed to a column slice), which means the use of an ordered partitioner. An ordered partitioner is almost always a Bad Idea.
Another challenge comes from the need to increment the item size, as this calls for the use of a counter column family. Counter column families store counter values only.
Setting aside the need for a range of box IDs for a moment, you could model this using multiple tables in CQL3 as follows:
CREATE TABLE boxes (
id int PRIMARY KEY,
belongs_to_user text,
box_title text,
);
CREATE INDEX useridx on boxes (belongs_to_user);
CREATE TABLE box_items (
id int,
item int,
size counter,
PRIMARY KEY(id, item)
);
CREATE TABLE box_item_names (
id int PRIMARY KEY,
item int,
name text
);
BEGIN BATCH
INSERT INTO boxes (id, belongs_to_user, box_title) VALUES (23442, 'user1', 'the box title');
INSERT INTO box_items (id, item, name) VALUES (23442, 1, 'itemname1');
INSERT INTO box_items (id, item, name) VALUES (23442, 1, 'itemname2');
UPDATE box_items SET size = size + 44 WHERE id = 23442 AND item = 1;
UPDATE box_items SET size = size + 24 WHERE id = 23442 AND item = 2;
APPLY BATCH
-- Get items for box by ID
SELECT size FROM box_items WHERE id = 23442 AND item = 1;
-- Boxes by user ID
SELECT * FROM boxes WHERE belongs_to_user = 'user1';
It's important to note that the BATCH mutation above is both atomic, and isolated.
Technically speaking, you could also denormalize all of this into a single table. For example:
CREATE TABLE boxes (
id int,
belongs_to_user text,
box_title text,
item int,
name text,
size counter,
PRIMARY KEY(id, item, belongs_to_user, box_title, name)
);
UPDATE boxes set size = item_size + 44 WHERE id = 23442 AND belongs_to_user = 'user1'
AND box_title = 'the box title' AND name = 'itemname1' AND item = 1;
SELECT item, name, size FROM boxes WHERE id = 23442;
However, this provides no guarantees of correctness. For example, this model makes it possible for items of the same box to have different users, or titles. And, since this makes boxes a counter column family, it limits how you can evolve the schema in the future.
I think in PlayOrm's objects first, then show the column model below....
Box {
#NoSqlId
String id;
#NoSqlEmbedded
List<Item> items;
}
User {
#NoSqlId
TimeUUID uuid;
#OneToMany
List<Box> boxes;
}
The User then is a row like so
rowkey = uuid=<someuuid> boxes.fkToBox35 = null, boxes.fktoBox37=null, boxes.fkToBox38=null
Note, the form of the above is columname=value where some of the columnnames are composite and some are not.
The box is more interesting and say Item has fields name and idnumber, then box row would be
rowkey = id=myid, items.item23.name=playdo, items.item23.idnumber=5634, itesm.item56.name=pencil, items.item56.idnumber=7894
I am not sure what you meant though on get the top 20 boxes? top boxes meaning by the number of items in them?
Dean
You can use Query-Driven Methodology, for data modeling.You have the three broad access paths:
1) partition per query
2) partition+ per query (one or more partitions)
3) table or table+ per query
The most efficient option is the “partition per query”. This article can help you in this case, step-by-step. it's sample is exactly a one-to-many relation.
And according to this, you will have several tables with some similar columns. You can manage this, by Materialized View or batch-log(as alternative approach).